/usr/share/php/Composer/Command/SuggestsCommand.php is in composer 1.6.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | <?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 Composer\Repository\PlatformRepository;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class SuggestsCommand extends BaseCommand
{
protected function configure()
{
$this
->setName('suggests')
->setDescription('Shows package suggestions.')
->setDefinition(array(
new InputOption('by-package', null, InputOption::VALUE_NONE, 'Groups output by suggesting package'),
new InputOption('by-suggestion', null, InputOption::VALUE_NONE, 'Groups output by suggested package'),
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 a sorted list of suggested packages.
Enabling <info>-v</info> implies <info>--by-package --by-suggestion</info>, showing both lists.
EOT
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$lock = $this->getComposer()->getLocker()->getLockData();
if (empty($lock)) {
throw new \RuntimeException('Lockfile seems to be empty?');
}
$packages = $lock['packages'];
if (!$input->getOption('no-dev')) {
$packages += $lock['packages-dev'];
}
$filter = $input->getArgument('packages');
// First assemble lookup list of packages that are installed, replaced or provided
$installed = array();
foreach ($packages as $package) {
$installed[] = $package['name'];
if (!empty($package['provide'])) {
$installed = array_merge($installed, array_keys($package['provide']));
}
if (!empty($package['replace'])) {
$installed = array_merge($installed, array_keys($package['replace']));
}
}
// Undub and sort the install list into a sorted lookup array
$installed = array_flip($installed);
ksort($installed);
// Init platform repo
$platform = new PlatformRepository(array(), $this->getComposer()->getConfig()->get('platform') ?: array());
// Next gather all suggestions that are not in that list
$suggesters = array();
$suggested = array();
foreach ($packages as $package) {
$packageName = $package['name'];
if ((!empty($filter) && !in_array($packageName, $filter)) || empty($package['suggest'])) {
continue;
}
foreach ($package['suggest'] as $suggestion => $reason) {
if (false === strpos('/', $suggestion) && null !== $platform->findPackage($suggestion, '*')) {
continue;
}
if (!isset($installed[$suggestion])) {
$suggesters[$packageName][$suggestion] = $reason;
$suggested[$suggestion][$packageName] = $reason;
}
}
}
ksort($suggesters);
ksort($suggested);
// Determine output mode
$mode = 0;
$io = $this->getIO();
if ($input->getOption('by-package') || $io->isVerbose()) {
$mode |= 1;
}
if ($input->getOption('by-suggestion')) {
$mode |= 2;
}
// Simple mode
if ($mode === 0) {
foreach (array_keys($suggested) as $suggestion) {
$io->write(sprintf('<info>%s</info>', $suggestion));
}
return;
}
// Grouped by package
if ($mode & 1) {
foreach ($suggesters as $suggester => $suggestions) {
$io->write(sprintf('<comment>%s</comment> suggests:', $suggester));
foreach ($suggestions as $suggestion => $reason) {
$io->write(sprintf(' - <info>%s</info>: %s', $suggestion, $reason ?: '*'));
}
$io->write('');
}
}
// Grouped by suggestion
if ($mode & 2) {
// Improve readability in full mode
if ($mode & 1) {
$io->write(str_repeat('-', 78));
}
foreach ($suggested as $suggestion => $suggesters) {
$io->write(sprintf('<comment>%s</comment> is suggested by:', $suggestion));
foreach ($suggesters as $suggester => $reason) {
$io->write(sprintf(' - <info>%s</info>: %s', $suggester, $reason ?: '*'));
}
$io->write('');
}
}
}
}
|