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.

73 lines
2.1 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\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'),
))
->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();
}
$packages = $lock['packages'];
if (!$input->getOption('no-dev')) {
$packages += $lock['packages-dev'];
}
foreach ($packages as $package) {
if (!empty($package['suggest'])) {
$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));
}
}
}
}
}