From 2552f4c65e2d9ebf0487a8feea4afa0e37f7a20b Mon Sep 17 00:00:00 2001 From: Gerry Vandermaesen Date: Mon, 11 Feb 2013 16:05:13 +0100 Subject: [PATCH 1/2] Added option to only show available packages Added the --available (-a) option to the show command to only list the available packages, similar to the --installed and --platform options. Additionally changed the output formatting when limiting the package result to remove the hierarchy when only one type is being showed. This facilitates parsing of a list of packages (for example for shell scripting and completion). --- src/Composer/Command/ShowCommand.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 2f8a4585a..0eaaade29 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -43,6 +43,7 @@ class ShowCommand extends Command new InputArgument('version', InputArgument::OPTIONAL, 'Version to inspect'), new InputOption('installed', 'i', InputOption::VALUE_NONE, 'List installed packages only'), new InputOption('platform', 'p', InputOption::VALUE_NONE, 'List platform packages only'), + new InputOption('available', 'a', InputOption::VALUE_NONE, 'List available packages only'), new InputOption('self', 's', InputOption::VALUE_NONE, 'Show the root package information'), new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables display of dev-require packages.'), )) @@ -78,6 +79,9 @@ EOT $repos = $installedRepo = $platformRepo; } elseif ($input->getOption('installed')) { $repos = $installedRepo = $getRepositories($this->getComposer(), $input->getOption('dev')); + } elseif ($input->getOption('available')) { + $installedRepo = $platformRepo; + $repos = new CompositeRepository(Factory::createDefaultRepositories($this->getIO())); } elseif ($composer = $this->getComposer(false)) { $localRepo = $getRepositories($composer, $input->getOption('dev')); $installedRepo = new CompositeRepository(array($localRepo, $platformRepo)); @@ -137,12 +141,17 @@ EOT foreach (array('platform:' => true, 'available:' => false, 'installed:' => true) as $type => $showVersion) { if (isset($packages[$type])) { - $output->writeln($type); + $tree = !$input->getOption('platform') && !$input->getOption('installed') && !$input->getOption('available'); + if ($tree) { + $output->writeln($type); + } ksort($packages[$type]); foreach ($packages[$type] as $package) { - $output->writeln(' '.$package->getPrettyName() .' '.($showVersion ? '['.$this->versionParser->formatVersion($package).']' : '').' : '. strtok($package->getDescription(), "\r\n")); + $output->writeln(($tree ? ' ' : '').$package->getPrettyName().' '.($showVersion ? '['.$this->versionParser->formatVersion($package).']' : '').' : '. strtok($package->getDescription(), "\r\n")); + } + if ($tree) { + $output->writeln(''); } - $output->writeln(''); } } } From 77290069a2ebea76bd3d140b5932cc033079f639 Mon Sep 17 00:00:00 2001 From: Gerry Vandermaesen Date: Mon, 11 Feb 2013 16:13:43 +0100 Subject: [PATCH 2/2] Added option to only show package names Added the --name-only (-N) option to the show command to only list package names (and exclude version and description). This is useful to produce a list of package names to be parsed by a shell script for example (bash completion comes to mind). --- src/Composer/Command/ShowCommand.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 0eaaade29..c8cfed416 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -46,6 +46,7 @@ class ShowCommand extends Command new InputOption('available', 'a', InputOption::VALUE_NONE, 'List available packages only'), new InputOption('self', 's', InputOption::VALUE_NONE, 'Show the root package information'), new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables display of dev-require packages.'), + new InputOption('name-only', 'N', InputOption::VALUE_NONE, 'List package names only'), )) ->setHelp(<<writeln(($tree ? ' ' : '').$package->getPrettyName().' '.($showVersion ? '['.$this->versionParser->formatVersion($package).']' : '').' : '. strtok($package->getDescription(), "\r\n")); + if ($input->getOption('name-only')) { + $output->writeln(($tree ? ' ' : '').$package->getPrettyName()); + } else { + $output->writeln(($tree ? ' ' : '').$package->getPrettyName().' '.($showVersion ? '['.$this->versionParser->formatVersion($package).']' : '').' : '. strtok($package->getDescription(), "\r\n")); + } } if ($tree) { $output->writeln('');