浏览代码

[Command] Add suggests command

Gusakov Nikita 11 年之前
父节点
当前提交
f1af16984e
共有 3 个文件被更改,包括 71 次插入0 次删除
  1. 11 0
      doc/03-cli.md
  2. 59 0
      src/Composer/Command/SuggestsCommand.php
  3. 1 0
      src/Composer/Console/Application.php

+ 11 - 0
doc/03-cli.md

@@ -294,6 +294,17 @@ in your browser.
 
 * **--homepage (-H):** Open the homepage instead of the repository URL.
 
+## suggests
+
+To list all of vendors suggesting to install packages, you can use the `suggests` command.
+
+    $ php composer.phar suggests
+
+
+### Options
+
+* **--dev:** Show dev suggests.
+
 ## depends
 
 The `depends` command tells you which other packages depend on a certain

+ 59 - 0
src/Composer/Command/SuggestsCommand.php

@@ -0,0 +1,59 @@
+<?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\OutputInterface;
+
+/**
+ * @author Gusakov Nikita <dev@nkt.me>
+ */
+class SuggestsCommand extends Command
+{
+    protected function configure()
+    {
+        $this
+            ->setName('suggests')
+            ->setDescription('Show packages suggests')
+            ->setDefinition(array(
+                new InputOption('dev', null, InputOption::VALUE_NONE, 'Show dev suggests'),
+            ))
+            ->setHelp(<<<EOT
+
+The <info>suggests</info> command show packages that suggesting to install other packages.
+
+EOT
+            );
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $lockData = $this->getComposer()->getLocker()->getLockData();
+        $this->printSuggests($output, $lockData['packages']);
+        if ($input->getOption('dev')) {
+            $this->printSuggests($output, $lockData['packages-dev']);
+        }
+    }
+
+    private function printSuggests(OutputInterface $output, array $packages)
+    {
+        foreach ($packages as $package) {
+            if (isset($package['suggest'])) {
+                foreach ($package['suggest'] as $target => $reason) {
+                    $output->writeln($package['name'].' suggests installing '.$target.' ('.$reason.')');
+                }
+            }
+        }
+    }
+}

+ 1 - 0
src/Composer/Console/Application.php

@@ -272,6 +272,7 @@ class Application extends BaseApplication
         $commands[] = new Command\SearchCommand();
         $commands[] = new Command\ValidateCommand();
         $commands[] = new Command\ShowCommand();
+        $commands[] = new Command\SuggestsCommand();
         $commands[] = new Command\RequireCommand();
         $commands[] = new Command\DumpAutoloadCommand();
         $commands[] = new Command\StatusCommand();