2014-03-17 11:26:19 +00:00
|
|
|
<?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;
|
|
|
|
|
2015-06-23 19:29:48 +00:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
2014-03-17 11:26:19 +00:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2015-06-23 19:04:06 +00:00
|
|
|
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
2014-03-17 11:26:19 +00:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2015-06-23 19:04:06 +00:00
|
|
|
use Symfony\Component\Finder\Exception\AccessDeniedException;
|
2014-03-17 11:26:19 +00:00
|
|
|
|
|
|
|
class SuggestsCommand extends Command
|
|
|
|
{
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('suggests')
|
2015-06-23 19:04:06 +00:00
|
|
|
->setDescription('Show package suggestions')
|
2014-03-17 11:26:19 +00:00
|
|
|
->setDefinition(array(
|
2015-06-23 19:04:06 +00:00
|
|
|
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Exclude suggestions from require-dev packages'),
|
2015-06-23 19:29:48 +00:00
|
|
|
new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Packages that you want to list suggestions from.'),
|
2014-03-17 11:26:19 +00:00
|
|
|
))
|
|
|
|
->setHelp(<<<EOT
|
|
|
|
|
2015-06-23 19:04:06 +00:00
|
|
|
The <info>%command.name%</info> command shows suggested packages.
|
2014-03-17 11:26:19 +00:00
|
|
|
|
|
|
|
EOT
|
2015-06-23 19:04:06 +00:00
|
|
|
)
|
|
|
|
;
|
2014-03-17 11:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2015-06-23 19:04:06 +00:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
2015-06-23 19:29:48 +00:00
|
|
|
$list = $lock['packages'];
|
2015-06-23 19:04:06 +00:00
|
|
|
|
|
|
|
if (!$input->getOption('no-dev')) {
|
2015-06-23 19:29:48 +00:00
|
|
|
$list += $lock['packages-dev'];
|
2014-03-17 11:26:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 19:29:48 +00:00
|
|
|
$packages = $input->getArgument('packages');
|
|
|
|
|
|
|
|
foreach ($list as $package) {
|
|
|
|
if (!empty($package['suggest']) && (empty($packages) || in_array($package['name'], $packages))) {
|
2015-06-23 19:04:06 +00:00
|
|
|
$stderr->writeln(sprintf('%s suggests:', $package['name']));
|
2014-03-17 11:26:19 +00:00
|
|
|
foreach ($package['suggest'] as $target => $reason) {
|
2015-06-23 19:04:06 +00:00
|
|
|
if (empty($reason)) {
|
|
|
|
$reason = '*';
|
|
|
|
}
|
|
|
|
|
|
|
|
$output->writeln(sprintf('<info>%s</info>: <comment>%s</comment>', $target, $reason));
|
2014-03-17 11:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|