reworked suggests command
parent
f1af16984e
commit
760eeb0b03
|
@ -296,14 +296,11 @@ in your browser.
|
||||||
|
|
||||||
## suggests
|
## suggests
|
||||||
|
|
||||||
To list all of vendors suggesting to install packages, you can use the `suggests` command.
|
Lists all packages suggested by currently installed set of packages.
|
||||||
|
|
||||||
$ php composer.phar suggests
|
|
||||||
|
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
* **--dev:** Show dev suggests.
|
* **--no-dev:** Exludes suggestions from `require-dev` packages.
|
||||||
|
|
||||||
## depends
|
## depends
|
||||||
|
|
||||||
|
|
|
@ -14,44 +14,57 @@ namespace Composer\Command;
|
||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Finder\Exception\AccessDeniedException;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Gusakov Nikita <dev@nkt.me>
|
|
||||||
*/
|
|
||||||
class SuggestsCommand extends Command
|
class SuggestsCommand extends Command
|
||||||
{
|
{
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('suggests')
|
->setName('suggests')
|
||||||
->setDescription('Show packages suggests')
|
->setDescription('Show package suggestions')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputOption('dev', null, InputOption::VALUE_NONE, 'Show dev suggests'),
|
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Exclude suggestions from require-dev packages'),
|
||||||
))
|
))
|
||||||
->setHelp(<<<EOT
|
->setHelp(<<<EOT
|
||||||
|
|
||||||
The <info>suggests</info> command show packages that suggesting to install other packages.
|
The <info>%command.name%</info> command shows suggested packages.
|
||||||
|
|
||||||
EOT
|
EOT
|
||||||
);
|
)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$lockData = $this->getComposer()->getLocker()->getLockData();
|
$lock = $this->getComposer()->getLocker()->getLockData();
|
||||||
$this->printSuggests($output, $lockData['packages']);
|
|
||||||
if ($input->getOption('dev')) {
|
if (empty($lock)) {
|
||||||
$this->printSuggests($output, $lockData['packages-dev']);
|
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'];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function printSuggests(OutputInterface $output, array $packages)
|
|
||||||
{
|
|
||||||
foreach ($packages as $package) {
|
foreach ($packages as $package) {
|
||||||
if (isset($package['suggest'])) {
|
if (!empty($package['suggest'])) {
|
||||||
|
$stderr->writeln(sprintf('%s suggests:', $package['name']));
|
||||||
foreach ($package['suggest'] as $target => $reason) {
|
foreach ($package['suggest'] as $target => $reason) {
|
||||||
$output->writeln($package['name'].' suggests installing '.$target.' ('.$reason.')');
|
if (empty($reason)) {
|
||||||
|
$reason = '*';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output->writeln(sprintf('<info>%s</info>: <comment>%s</comment>', $target, $reason));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue