1
0
Fork 0

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

pull/5220/head
Jordi Boggiano 2016-04-19 11:31:41 +01:00
parent 89cfde051d
commit 21a9f21cc8
2 changed files with 28 additions and 6 deletions

View File

@ -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

View File

@ -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,19 +209,23 @@ EOT
}
if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
foreach ($repo->getProviderNames() as $name) {
if (preg_match($packageFilter, $name)) {
$packages[$type][$name] = $name;
}
}
} else {
foreach ($repo->getPackages() as $package) {
if (!isset($packages[$type][$package->getName()])
|| !is_object($packages[$type][$package->getName()])
|| version_compare($packages[$type][$package->getName()]->getVersion(), $package->getVersion(), '<')
) {
if (preg_match($packageFilter, $package->getName())) {
$packages[$type][$package->getName()] = $package;
}
}
}
}
}
$showAllTypes = $input->getOption('all');
$indent = $showAllTypes ? ' ' : '';