From 3dffdc8705b24f8535c676e36e4e4d061acc9531 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Wed, 24 Jun 2015 11:06:21 +0200 Subject: [PATCH] don't suggest packages already installed --- src/Composer/Command/SuggestsCommand.php | 50 ++++++++++++++++-------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/Composer/Command/SuggestsCommand.php b/src/Composer/Command/SuggestsCommand.php index 13558b693..c6f7385fd 100644 --- a/src/Composer/Command/SuggestsCommand.php +++ b/src/Composer/Command/SuggestsCommand.php @@ -45,38 +45,54 @@ EOT throw new \RuntimeException('Lockfile seems to be empty?'); } - $io = $this->getIO(); - $list = $lock['packages']; + $packages = $lock['packages']; if (!$input->getOption('no-dev')) { - $list += $lock['packages-dev']; + $packages += $lock['packages-dev']; } - $packages = $input->getArgument('packages'); + $filter = $input->getArgument('packages'); - foreach ($list as $package) { - if (!empty($package['suggest']) && (empty($packages) || in_array($package['name'], $packages))) { - $this->printSuggestions($package['name'], $package['suggest']); + foreach ($packages as $package) { + if (empty($package['suggest'])) { + continue; } + + if (!empty($filter) && !in_array($package['name'], $filter)) { + continue; + } + + $this->printSuggestions($packages, $package['name'], $package['suggest']); } } - protected function printSuggestions($name, $suggests) + protected function printSuggestions($installed, $source, $suggestions) { - $io = $this->getIO(); + foreach ($suggestions as $suggestion => $reason) { + foreach ($installed as $package) { + if ($package['name'] === $suggestion) { + continue 2; + } + } - foreach ($suggests as $target => $reason) { if (empty($reason)) { $reason = '*'; } - if ($io->isVeryVerbose()) { - $io->write(sprintf('%s suggests %s: %s', $name, $target, $reason)); - } elseif ($io->isVerbose()) { - $io->write(sprintf('%s suggests %s', $name, $target)); - } else { - $io->write(sprintf('%s', $target)); - } + $this->printSuggestion($source, $suggestion, $reason); + } + } + + protected function printSuggestion($package, $suggestion, $reason) + { + $io = $this->getIO(); + + if ($io->isVeryVerbose()) { + $io->write(sprintf('%s suggests %s: %s', $package, $suggestion, $reason)); + } elseif ($io->isVerbose()) { + $io->write(sprintf('%s suggests %s', $package, $suggestion)); + } else { + $io->write(sprintf('%s', $suggestion)); } } }