Browse Source

Only show direct dependencies suggestions by default, add --all flag to see all in suggest command, fixes #8660

Jordi Boggiano 5 years ago
parent
commit
94e6cfc521
2 changed files with 8 additions and 0 deletions
  1. 2 0
      doc/03-cli.md
  2. 6 0
      src/Composer/Command/SuggestsCommand.php

+ 2 - 0
doc/03-cli.md

@@ -416,6 +416,8 @@ If you only want a list of suggested package names, use `--list`.
 
 * **--by-package:** Groups output by suggesting package (default).
 * **--by-suggestion:** Groups output by suggested package.
+* **--all:** Show suggestions from all dependencies, including transitive ones (by
+  default only direct dependencies' suggestions are shown).
 * **--list:** Show only list of suggested package names.
 * **--no-dev:** Excludes suggestions from `require-dev` packages.
 

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

@@ -31,6 +31,7 @@ class SuggestsCommand extends BaseCommand
             ->setDefinition(array(
                 new InputOption('by-package', null, InputOption::VALUE_NONE, 'Groups output by suggesting package (default)'),
                 new InputOption('by-suggestion', null, InputOption::VALUE_NONE, 'Groups output by suggested package'),
+                new InputOption('all', 'a', InputOption::VALUE_NONE, 'Show suggestions from all dependencies, including transitive ones'),
                 new InputOption('list', null, InputOption::VALUE_NONE, 'Show only list of suggested package names'),
                 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.'),
@@ -70,6 +71,11 @@ EOT
         $reporter = new SuggestedPackagesReporter($this->getIO());
 
         $filter = $input->getArgument('packages');
+        if (empty($filter) && !$input->getOption('all')) {
+            $filter = array_map(function ($link) {
+                return $link->getTarget();
+            }, array_merge($composer->getPackage()->getRequires(), $composer->getPackage()->getDevRequires()));
+        }
         foreach ($installedRepo->getPackages() as $package) {
             if (!empty($filter) && !in_array($package->getName(), $filter)) {
                 continue;