diff --git a/doc/03-cli.md b/doc/03-cli.md index 8c5bf2f05..5b6e0fb00 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -296,14 +296,11 @@ in your browser. ## suggests -To list all of vendors suggesting to install packages, you can use the `suggests` command. - - $ php composer.phar suggests - +Lists all packages suggested by currently installed set of packages. ### Options -* **--dev:** Show dev suggests. +* **--no-dev:** Exludes suggestions from `require-dev` packages. ## depends diff --git a/src/Composer/Command/SuggestsCommand.php b/src/Composer/Command/SuggestsCommand.php index 18e3cf788..fd2193f9a 100644 --- a/src/Composer/Command/SuggestsCommand.php +++ b/src/Composer/Command/SuggestsCommand.php @@ -14,44 +14,57 @@ namespace Composer\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Finder\Exception\AccessDeniedException; -/** - * @author Gusakov Nikita - */ class SuggestsCommand extends Command { protected function configure() { $this ->setName('suggests') - ->setDescription('Show packages suggests') + ->setDescription('Show package suggestions') ->setDefinition(array( - new InputOption('dev', null, InputOption::VALUE_NONE, 'Show dev suggests'), + new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Exclude suggestions from require-dev packages'), )) ->setHelp(<<suggests command show packages that suggesting to install other packages. +The %command.name% command shows suggested packages. EOT - ); + ) + ; } protected function execute(InputInterface $input, OutputInterface $output) { - $lockData = $this->getComposer()->getLocker()->getLockData(); - $this->printSuggests($output, $lockData['packages']); - if ($input->getOption('dev')) { - $this->printSuggests($output, $lockData['packages-dev']); + $lock = $this->getComposer()->getLocker()->getLockData(); + + if (empty($lock)) { + throw new \RuntimeException('Lockfile seems to be empty?'); + } + + $stderr = $output; + if ($output instanceof ConsoleOutputInterface) { + $stderr = $output->getErrorOutput(); + } + + $packages = $lock['packages']; + + if (!$input->getOption('no-dev')) { + $packages += $lock['packages-dev']; } - } - private function printSuggests(OutputInterface $output, array $packages) - { foreach ($packages as $package) { - if (isset($package['suggest'])) { + if (!empty($package['suggest'])) { + $stderr->writeln(sprintf('%s suggests:', $package['name'])); foreach ($package['suggest'] as $target => $reason) { - $output->writeln($package['name'].' suggests installing '.$target.' ('.$reason.')'); + if (empty($reason)) { + $reason = '*'; + } + + $output->writeln(sprintf('%s: %s', $target, $reason)); } } }