diff --git a/src/Composer/Command/DebugPackagesCommand.php b/src/Composer/Command/DebugPackagesCommand.php deleted file mode 100644 index e3d196466..000000000 --- a/src/Composer/Command/DebugPackagesCommand.php +++ /dev/null @@ -1,90 +0,0 @@ - - * Jordi Boggiano - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\Command; - -use Composer\Autoload\AutoloadGenerator; -use Composer\DependencyResolver; -use Composer\DependencyResolver\Pool; -use Composer\DependencyResolver\Request; -use Composer\DependencyResolver\Operation; -use Composer\Package\LinkConstraint\VersionConstraint; -use Composer\Repository\CompositeRepository; -use Composer\Repository\PlatformRepository; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Output\OutputInterface; - -/** - * @author Jordi Boggiano - */ -class DebugPackagesCommand extends Command -{ - protected function configure() - { - $this - ->setName('debug:packages') - ->setDescription('Lists all existing packages and their version') - ->setDefinition(array( - new InputOption('local', null, InputOption::VALUE_NONE, 'list locally installed packages only'), - new InputOption('platform', null, InputOption::VALUE_NONE, 'list platform packages only'), - )) - ->setHelp(<<php composer.phar debug:packages - -EOT - ) - ; - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $composer = $this->getComposer(); - - // create local repo, this contains all packages that are installed in the local project - $localRepo = $composer->getRepositoryManager()->getLocalRepository(); - // create installed repo, this contains all local packages + platform packages (php & extensions) - $installedRepo = new CompositeRepository(array($localRepo, new PlatformRepository())); - - if ($input->getOption('local')) { - foreach ($localRepo->getPackages() as $package) { - $output->writeln('local: ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . ' (' . $package->getVersion() . ')'); - } - - return; - } - - if ($input->getOption('platform')) { - $repos = array_diff($installedRepo->getPackages(), $localRepo->getPackages()); - foreach ($repos as $package) { - $output->writeln('plattform: ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . ' (' . $package->getVersion() . ')'); - } - - return; - } - - foreach ($installedRepo->getPackages() as $package) { - if ($localRepo->hasPackage($package)) { - $output->writeln('installed: ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . ' (' . $package->getVersion() . ')'); - } else { - $output->writeln('platform: ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . ' (' . $package->getName() . ' ' . $package->getVersion() . ')'); - } - } - - foreach ($composer->getRepositoryManager()->getRepositories() as $repository) { - foreach ($repository->getPackages() as $package) { - $output->writeln('available: ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . ' (' . $package->getName() . ' ' . $package->getVersion() . ')'); - } - } - } - -} \ No newline at end of file diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index a860a83af..4450966b3 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -16,6 +16,7 @@ use Composer\Composer; use Composer\Package\PackageInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Composer\Repository\CompositeRepository; use Composer\Repository\PlatformRepository; @@ -32,14 +33,16 @@ class ShowCommand extends Command { $this ->setName('show') - ->setDescription('Show package details') + ->setDescription('Show information about packages') ->setDefinition(array( - new InputArgument('package', InputArgument::REQUIRED, 'the package to inspect'), - new InputArgument('version', InputArgument::OPTIONAL, 'the version'), + new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect'), + new InputArgument('version', InputArgument::OPTIONAL, 'Version to inspect'), + new InputOption('installed', null, InputOption::VALUE_NONE, 'List installed packages only'), + new InputOption('platform', null, InputOption::VALUE_NONE, 'List platform packages only'), )) ->setHelp(<<php composer.phar show composer/composer master-dev +The show command displays detailed information about a package, or +lists all packages available. EOT ) @@ -48,25 +51,48 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { - if ($composer = $this->getComposer(false)) { + // init repos + $platformRepo = new PlatformRepository; + if ($input->getOption('platform')) { + $repos = $installedRepo = $platformRepo; + } elseif ($input->getOption('installed')) { + $composer = $this->getComposer(); + $repos = $installedRepo = $composer->getRepositoryManager()->getLocalRepository(); + } elseif ($composer = $this->getComposer(false)) { $localRepo = $composer->getRepositoryManager()->getLocalRepository(); - $installedRepo = new CompositeRepository(array($localRepo, new PlatformRepository())); + $installedRepo = new CompositeRepository(array($localRepo, $platformRepo)); $repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories())); } else { $output->writeln('No composer.json found in the current directory, showing packages from packagist.org'); - $installedRepo = new PlatformRepository; + $installedRepo = $platformRepo; $repos = new CompositeRepository(array($installedRepo, new ComposerRepository(array('url' => 'http://packagist.org')))); } - $package = $this->getPackage($input, $output, $installedRepo, $repos); - if (!$package) { - throw new \InvalidArgumentException('no package found'); + // show single package or single version + if ($input->getArgument('package')) { + $package = $this->getPackage($input, $output, $installedRepo, $repos); + if (!$package) { + throw new \InvalidArgumentException('Package '.$input->getArgument('package').' not found'); + } + + $this->printMeta($input, $output, $package, $installedRepo, $repos); + $this->printLinks($input, $output, $package, 'requires'); + $this->printLinks($input, $output, $package, 'recommends'); + $this->printLinks($input, $output, $package, 'replaces'); + return; } - $this->printMeta($input, $output, $package, $installedRepo, $repos); - $this->printLinks($input, $output, $package, 'requires'); - $this->printLinks($input, $output, $package, 'recommends'); - $this->printLinks($input, $output, $package, 'replaces'); + // list packages + foreach ($repos->getPackages() as $package) { + if ($platformRepo->hasPackage($package)) { + $type = 'platform: '; + } elseif ($installedRepo->hasPackage($package)) { + $type = 'installed: '; + } else { + $type = 'available: '; + } + $output->writeln($type . ' ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . ' (' . $package->getVersion() . ')'); + } } /**