You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB
PHTML

<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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(<<<EOT
The <info>%command.name%</info> 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('<info>%s</info>: <comment>%s</comment>', $target, $reason));
}
}
}
}
}