From f1af16984e44aa4e04a416f26eb2973a2449784f Mon Sep 17 00:00:00 2001 From: Gusakov Nikita Date: Mon, 17 Mar 2014 15:26:19 +0400 Subject: [PATCH] [Command] Add suggests command --- doc/03-cli.md | 11 +++++ src/Composer/Command/SuggestsCommand.php | 59 ++++++++++++++++++++++++ src/Composer/Console/Application.php | 1 + 3 files changed, 71 insertions(+) create mode 100644 src/Composer/Command/SuggestsCommand.php diff --git a/doc/03-cli.md b/doc/03-cli.md index b8921511c..8c5bf2f05 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -294,6 +294,17 @@ in your browser. * **--homepage (-H):** Open the homepage instead of the repository URL. +## suggests + +To list all of vendors suggesting to install packages, you can use the `suggests` command. + + $ php composer.phar suggests + + +### Options + +* **--dev:** Show dev suggests. + ## depends The `depends` command tells you which other packages depend on a certain diff --git a/src/Composer/Command/SuggestsCommand.php b/src/Composer/Command/SuggestsCommand.php new file mode 100644 index 000000000..18e3cf788 --- /dev/null +++ b/src/Composer/Command/SuggestsCommand.php @@ -0,0 +1,59 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Command; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * @author Gusakov Nikita + */ +class SuggestsCommand extends Command +{ + protected function configure() + { + $this + ->setName('suggests') + ->setDescription('Show packages suggests') + ->setDefinition(array( + new InputOption('dev', null, InputOption::VALUE_NONE, 'Show dev suggests'), + )) + ->setHelp(<<suggests command show packages that suggesting to install other 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']); + } + } + + private function printSuggests(OutputInterface $output, array $packages) + { + foreach ($packages as $package) { + if (isset($package['suggest'])) { + foreach ($package['suggest'] as $target => $reason) { + $output->writeln($package['name'].' suggests installing '.$target.' ('.$reason.')'); + } + } + } + } +} diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index ee4f4e9c0..62654bf8b 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -272,6 +272,7 @@ class Application extends BaseApplication $commands[] = new Command\SearchCommand(); $commands[] = new Command\ValidateCommand(); $commands[] = new Command\ShowCommand(); + $commands[] = new Command\SuggestsCommand(); $commands[] = new Command\RequireCommand(); $commands[] = new Command\DumpAutoloadCommand(); $commands[] = new Command\StatusCommand();