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;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
2016-02-19 22:56:46 +00:00
|
|
|
class SuggestsCommand extends BaseCommand
|
2014-03-17 11:26:19 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2015-07-04 11:02:57 +00:00
|
|
|
With <info>-v</info> you also see which package suggested it and why.
|
|
|
|
|
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?');
|
|
|
|
}
|
|
|
|
|
2015-06-24 09:06:21 +00:00
|
|
|
$packages = $lock['packages'];
|
2015-06-23 19:04:06 +00:00
|
|
|
|
|
|
|
if (!$input->getOption('no-dev')) {
|
2015-06-24 09:06:21 +00:00
|
|
|
$packages += $lock['packages-dev'];
|
2014-03-17 11:26:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 09:06:21 +00:00
|
|
|
$filter = $input->getArgument('packages');
|
|
|
|
|
|
|
|
foreach ($packages as $package) {
|
|
|
|
if (empty($package['suggest'])) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-06-23 19:29:48 +00:00
|
|
|
|
2015-06-24 09:06:21 +00:00
|
|
|
if (!empty($filter) && !in_array($package['name'], $filter)) {
|
|
|
|
continue;
|
2015-06-23 20:03:35 +00:00
|
|
|
}
|
2015-06-24 09:06:21 +00:00
|
|
|
|
|
|
|
$this->printSuggestions($packages, $package['name'], $package['suggest']);
|
2015-06-23 20:03:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-24 09:06:21 +00:00
|
|
|
protected function printSuggestions($installed, $source, $suggestions)
|
2015-06-23 20:03:35 +00:00
|
|
|
{
|
2015-06-24 09:06:21 +00:00
|
|
|
foreach ($suggestions as $suggestion => $reason) {
|
|
|
|
foreach ($installed as $package) {
|
|
|
|
if ($package['name'] === $suggestion) {
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 20:03:35 +00:00
|
|
|
|
|
|
|
if (empty($reason)) {
|
|
|
|
$reason = '*';
|
|
|
|
}
|
2015-06-23 19:04:06 +00:00
|
|
|
|
2015-06-24 09:06:21 +00:00
|
|
|
$this->printSuggestion($source, $suggestion, $reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function printSuggestion($package, $suggestion, $reason)
|
|
|
|
{
|
|
|
|
$io = $this->getIO();
|
|
|
|
|
2015-07-04 11:02:57 +00:00
|
|
|
if ($io->isVerbose()) {
|
2015-06-24 09:06:21 +00:00
|
|
|
$io->write(sprintf('<comment>%s</comment> suggests <info>%s</info>: %s', $package, $suggestion, $reason));
|
|
|
|
} else {
|
|
|
|
$io->write(sprintf('<info>%s</info>', $suggestion));
|
2014-03-17 11:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|