1
0
Fork 0

Merge debug:packages into the show command (if used without package arg)

pull/281/head
Jordi Boggiano 2012-02-09 16:30:55 +01:00
parent 0e7c0d918f
commit 6971657ad0
2 changed files with 41 additions and 105 deletions

View File

@ -1,90 +0,0 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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 <j.boggiano@seld.be>
*/
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(<<<EOT
<info>php composer.phar debug:packages</info>
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('<info>local:</info> ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getVersion() . ')</comment>');
}
return;
}
if ($input->getOption('platform')) {
$repos = array_diff($installedRepo->getPackages(), $localRepo->getPackages());
foreach ($repos as $package) {
$output->writeln('<info>plattform:</info> ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getVersion() . ')</comment>');
}
return;
}
foreach ($installedRepo->getPackages() as $package) {
if ($localRepo->hasPackage($package)) {
$output->writeln('<info>installed:</info> ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getVersion() . ')</comment>');
} else {
$output->writeln('<info>platform:</info> ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getName() . ' ' . $package->getVersion() . ')</comment>');
}
}
foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
foreach ($repository->getPackages() as $package) {
$output->writeln('<comment>available:</comment> ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getName() . ' ' . $package->getVersion() . ')</comment>');
}
}
}
}

View File

@ -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(<<<EOT
The show command displays detailed information about a package
<info>php composer.phar show composer/composer master-dev</info>
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 = '<info>platform: </info> ';
} elseif ($installedRepo->hasPackage($package)) {
$type = '<info>installed:</info> ';
} else {
$type = '<comment>available:</comment> ';
}
$output->writeln($type . ' ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getVersion() . ')</comment>');
}
}
/**