Bläddra i källkod

Add package filtering in show command, fixes #5212, closes #5215

Jordi Boggiano 9 år sedan
förälder
incheckning
21a9f21cc8
2 ändrade filer med 28 tillägg och 6 borttagningar
  1. 13 2
      doc/03-cli.md
  2. 15 4
      src/Composer/Command/ShowCommand.php

+ 13 - 2
doc/03-cli.md

@@ -274,6 +274,14 @@ To list all of the available packages, you can use the `show` command.
 php composer.phar show
 ```
 
+To filter the list you can pass a package mask using wildcards.
+
+```sh
+php composer.phar show monolog/*
+
+monolog/monolog 1.19.0 Sends your logs to files, sockets, inboxes, databases and various web services
+```
+
 If you want to see the details of a certain package, you can pass the package
 name.
 
@@ -305,10 +313,13 @@ php composer.phar show monolog/monolog 1.0.2
 
 ### Options
 
-* **--installed (-i):** List the packages that are installed.
+* **--all (-a):** List all packages available in all your repositories.
+* **--installed (-i):** List the packages that are installed (this is enabled by default, and deprecated).
 * **--platform (-p):** List only platform packages (php & extensions).
 * **--self (-s):** List the root package info.
-* **--tree (-t):** List the dependencies as a tree. Only usable when giving a single package name or combined with `-i`.
+* **--tree (-t):** List your dependencies as a tree. If you pass a package name it will show the dependency tree for that package.
+* **--name-only (-N):** List package names only.
+* **--path (-P):** List package paths.
 
 ## browse / home
 

+ 15 - 4
src/Composer/Command/ShowCommand.php

@@ -52,7 +52,7 @@ class ShowCommand extends BaseCommand
             ->setAliases(array('info'))
             ->setDescription('Show information about packages')
             ->setDefinition(array(
-                new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect'),
+                new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect. Or a name including a wildcard (*) to filter lists of packages instead.'),
                 new InputArgument('version', InputArgument::OPTIONAL, 'Version or version constraint to inspect'),
                 new InputOption('all', null, InputOption::VALUE_NONE, 'List all packages'),
                 new InputOption('installed', 'i', InputOption::VALUE_NONE, 'List installed packages only (enabled by default, only present for BC).'),
@@ -131,8 +131,10 @@ EOT
             $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
         }
 
+        $packageFilter = $input->getArgument('package');
+
         // show single package or single version
-        if ($input->getArgument('package') || !empty($package)) {
+        if (($packageFilter && false === strpos($packageFilter, '*')) || !empty($package)) {
             if (empty($package)) {
                 list($package, $versions) = $this->getPackage($installedRepo, $repos, $input->getArgument('package'), $input->getArgument('version'));
 
@@ -188,6 +190,11 @@ EOT
 
         // list packages
         $packages = array();
+        if ($packageFilter) {
+            $packageFilter = '{^'.str_replace('\\*', '.*?', preg_quote($packageFilter)).'$}i';
+        } else {
+            $packageFilter = '{.}';
+        }
 
         foreach ($repos as $repo) {
             if ($repo === $platformRepo) {
@@ -202,7 +209,9 @@ EOT
             }
             if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
                 foreach ($repo->getProviderNames() as $name) {
-                    $packages[$type][$name] = $name;
+                    if (preg_match($packageFilter, $name)) {
+                        $packages[$type][$name] = $name;
+                    }
                 }
             } else {
                 foreach ($repo->getPackages() as $package) {
@@ -210,7 +219,9 @@ EOT
                         || !is_object($packages[$type][$package->getName()])
                         || version_compare($packages[$type][$package->getName()]->getVersion(), $package->getVersion(), '<')
                     ) {
-                        $packages[$type][$package->getName()] = $package;
+                        if (preg_match($packageFilter, $package->getName())) {
+                            $packages[$type][$package->getName()] = $package;
+                        }
                     }
                 }
             }