* 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\InputArgument; 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; class SuggestsCommand extends Command { protected function configure() { $this ->setName('suggests') ->setDescription('Show package suggestions') ->setDefinition(array( new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Exclude suggestions from require-dev packages'), new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Packages that you want to list suggestions from.'), )) ->setHelp(<<%command.name% command shows suggested packages. EOT ) ; } protected function execute(InputInterface $input, OutputInterface $output) { $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(); } $list = $lock['packages']; if (!$input->getOption('no-dev')) { $list += $lock['packages-dev']; } $packages = $input->getArgument('packages'); foreach ($list as $package) { if (!empty($package['suggest']) && (empty($packages) || in_array($package['name'], $packages))) { $stderr->writeln(sprintf('%s suggests:', $package['name'])); foreach ($package['suggest'] as $target => $reason) { if (empty($reason)) { $reason = '*'; } $output->writeln(sprintf('%s: %s', $target, $reason)); } } } } }