Merge debug:packages into the show command (if used without package arg)
parent
0e7c0d918f
commit
6971657ad0
|
@ -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>');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -16,6 +16,7 @@ use Composer\Composer;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Composer\Repository\CompositeRepository;
|
use Composer\Repository\CompositeRepository;
|
||||||
use Composer\Repository\PlatformRepository;
|
use Composer\Repository\PlatformRepository;
|
||||||
|
@ -32,14 +33,16 @@ class ShowCommand extends Command
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('show')
|
->setName('show')
|
||||||
->setDescription('Show package details')
|
->setDescription('Show information about packages')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputArgument('package', InputArgument::REQUIRED, 'the package to inspect'),
|
new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect'),
|
||||||
new InputArgument('version', InputArgument::OPTIONAL, 'the version'),
|
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
|
->setHelp(<<<EOT
|
||||||
The show command displays detailed information about a package
|
The show command displays detailed information about a package, or
|
||||||
<info>php composer.phar show composer/composer master-dev</info>
|
lists all packages available.
|
||||||
|
|
||||||
EOT
|
EOT
|
||||||
)
|
)
|
||||||
|
@ -48,25 +51,48 @@ EOT
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
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();
|
$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()));
|
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
|
||||||
} else {
|
} else {
|
||||||
$output->writeln('No composer.json found in the current directory, showing packages from packagist.org');
|
$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'))));
|
$repos = new CompositeRepository(array($installedRepo, new ComposerRepository(array('url' => 'http://packagist.org'))));
|
||||||
}
|
}
|
||||||
|
|
||||||
$package = $this->getPackage($input, $output, $installedRepo, $repos);
|
// show single package or single version
|
||||||
if (!$package) {
|
if ($input->getArgument('package')) {
|
||||||
throw new \InvalidArgumentException('no package found');
|
$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);
|
// list packages
|
||||||
$this->printLinks($input, $output, $package, 'requires');
|
foreach ($repos->getPackages() as $package) {
|
||||||
$this->printLinks($input, $output, $package, 'recommends');
|
if ($platformRepo->hasPackage($package)) {
|
||||||
$this->printLinks($input, $output, $package, 'replaces');
|
$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>');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue