Adjustments to the show command
parent
7caf61fc66
commit
a2caa7c5e6
|
@ -12,22 +12,18 @@
|
||||||
|
|
||||||
namespace Composer\Command;
|
namespace Composer\Command;
|
||||||
|
|
||||||
use Composer\Repository\PlatformRepository;
|
use Composer\Composer;
|
||||||
|
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\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Composer\Package\Dumper\ArrayDumper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert Schönthal <seroscho@googlemail.com>
|
* @author Robert Schönthal <seroscho@googlemail.com>
|
||||||
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
*/
|
*/
|
||||||
class ShowCommand extends Command
|
class ShowCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
//holds the array dump of an package
|
|
||||||
private $dump;
|
|
||||||
private $output;
|
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -48,72 +44,70 @@ EOT
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$dumper = new ArrayDumper();
|
$composer = $this->getComposer();
|
||||||
$this->output = $output;
|
$package = $this->getPackage($input, $output, $composer);
|
||||||
$this->dump = $dumper->dump($this->getPackage($input));
|
if (!$package) {
|
||||||
|
throw new \InvalidArgumentException('no package found');
|
||||||
|
}
|
||||||
|
|
||||||
$this->printMeta($input);
|
$this->printMeta($input, $output, $package, $composer);
|
||||||
$this->printLinks('requires');
|
$this->printLinks($input, $output, $package, 'requires');
|
||||||
$this->printLinks('recommends');
|
$this->printLinks($input, $output, $package, 'recommends');
|
||||||
$this->printLinks('replaces');
|
$this->printLinks($input, $output, $package, 'replaces');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* finds a package by name and version if provided
|
* finds a package by name and version if provided
|
||||||
*
|
*
|
||||||
* @param InputInterface $input
|
* @param InputInterface $input
|
||||||
* @return PackageInterface
|
* @return PackageInterface
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
protected function getPackage(InputInterface $input)
|
protected function getPackage(InputInterface $input, OutputInterface $output, Composer $composer)
|
||||||
{
|
{
|
||||||
$composer = $this->getComposer();
|
// we have a name and a version so we can use ::findPackage
|
||||||
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
|
|
||||||
|
|
||||||
//we have a name and a version so we can use ::findPackage
|
|
||||||
if ($input->getArgument('version')) {
|
if ($input->getArgument('version')) {
|
||||||
return $composer->getRepositoryManager()->findPackage($input->getArgument('package'), $input->getArgument('version'));
|
return $composer->getRepositoryManager()->findPackage($input->getArgument('package'), $input->getArgument('version'));
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if we have a local installation so we can grab the right package/version
|
// check if we have a local installation so we can grab the right package/version
|
||||||
|
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
|
||||||
foreach ($localRepo->getPackages() as $package) {
|
foreach ($localRepo->getPackages() as $package) {
|
||||||
if ($package->getName() === $input->getArgument('package')) {
|
if ($package->getName() === $input->getArgument('package')) {
|
||||||
return $package;
|
return $package;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//we only have a name, so search for the first package where the name matches
|
// we only have a name, so search for the first package where the name matches
|
||||||
foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
|
foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
|
||||||
foreach ($repository->getPackages() as $package) {
|
foreach ($repository->getPackages() as $package) {
|
||||||
if ($package->getName() == $input->getArgument('package')) {
|
if ($package->getName() === $input->getArgument('package')) {
|
||||||
return $package;
|
return $package;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException('no package found');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* prints package meta data
|
* prints package meta data
|
||||||
*/
|
*/
|
||||||
protected function printMeta(InputInterface $input)
|
protected function printMeta(InputInterface $input, OutputInterface $output, PackageInterface $package, Composer $composer)
|
||||||
{
|
{
|
||||||
$this->output->writeln('<info>name</info> : ' . $this->dump['name']);
|
$output->writeln('<info>name</info> : ' . $package->getPrettyName());
|
||||||
$this->printVersions($input);
|
$this->printVersions($input, $output, $package, $composer);
|
||||||
$this->output->writeln('<info>type</info> : ' . $this->dump['type']);
|
$output->writeln('<info>type</info> : ' . $package->getType());
|
||||||
$this->output->writeln('<info>names</info> : ' . join(', ', $this->dump['names']));
|
$output->writeln('<info>names</info> : ' . join(', ', $package->getNames()));
|
||||||
$this->output->writeln('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $this->dump['source']['type'], $this->dump['source']['url'], $this->dump['source']['reference']));
|
$output->writeln('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
|
||||||
$this->output->writeln('<info>dist</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $this->dump['dist']['type'], $this->dump['dist']['url'], $this->dump['dist']['reference']));
|
$output->writeln('<info>dist</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
|
||||||
$this->output->writeln('<info>licence</info> : ' . join(', ', $this->dump['license']));
|
$output->writeln('<info>licence</info> : ' . join(', ', $package->getLicense()));
|
||||||
$this->output->writeln("\n<info>autoload</info>");
|
|
||||||
|
if ($package->getAutoload()) {
|
||||||
|
$output->writeln("\n<info>autoload</info>");
|
||||||
|
foreach ($package->getAutoload() as $type => $autoloads) {
|
||||||
|
$output->writeln('<comment>' . $type . '</comment>');
|
||||||
|
|
||||||
if (array_key_exists('autoload', $this->dump)) {
|
|
||||||
foreach ($this->dump['autoload'] as $type => $autoloads) {
|
|
||||||
$this->output->writeln('<comment>' . $type . '</comment>');
|
|
||||||
|
|
||||||
foreach ($autoloads as $name => $path) {
|
foreach ($autoloads as $name => $path) {
|
||||||
$this->output->writeln($name .' : '. $path);
|
$output->writeln($name . ' : ' . ($path ?: '.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,41 +116,45 @@ EOT
|
||||||
/**
|
/**
|
||||||
* prints all available versions of this package and highlights the installed one if any
|
* prints all available versions of this package and highlights the installed one if any
|
||||||
*/
|
*/
|
||||||
protected function printVersions(InputInterface $input)
|
protected function printVersions(InputInterface $input, OutputInterface $output, PackageInterface $package, Composer $composer)
|
||||||
{
|
{
|
||||||
if ($input->getArgument('version')) {
|
if ($input->getArgument('version')) {
|
||||||
$this->output->writeln('<info>version</info> : ' . $this->dump['version_normalized']);
|
$output->writeln('<info>version</info> : ' . $package->getPrettyVersion());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$versions = array();
|
$versions = array();
|
||||||
|
|
||||||
foreach ($this->getComposer()->getRepositoryManager()->getRepositories() as $repository) {
|
foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
|
||||||
foreach ($repository->getPackages() as $package) {
|
foreach ($repository->getPackages() as $version) {
|
||||||
if ($package->getName() === $this->dump['name']) {
|
if ($version->getName() === $package->getName()) {
|
||||||
$versions[] = $package->getPrettyVersion();
|
$versions[] = $version->getPrettyVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$versions = str_replace($this->dump['version'], '<info>' . $this->dump['version'] . '</info>', join(', ', $versions));
|
$versions = join(', ', $versions);
|
||||||
|
|
||||||
$this->output->writeln('<info>versions</info> : ' . $versions);
|
// highlight installed version
|
||||||
|
if ($composer->getRepositoryManager()->getLocalRepository()->hasPackage($package)) {
|
||||||
|
$versions = str_replace($package->getPrettyVersion(), '<info>* ' . $package->getPrettyVersion() . '</info>', $versions);
|
||||||
|
}
|
||||||
|
|
||||||
|
$output->writeln('<info>versions</info> : ' . $versions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* print link objects
|
* print link objects
|
||||||
*
|
*
|
||||||
* @param string $linksName
|
* @param string $linkType
|
||||||
*/
|
*/
|
||||||
protected function printLinks($linksName)
|
protected function printLinks(InputInterface $input, OutputInterface $output, PackageInterface $package, $linkType)
|
||||||
{
|
{
|
||||||
if (isset($this->dump[$linksName])) {
|
if ($links = $package->{'get'.ucfirst($linkType)}()) {
|
||||||
|
$output->writeln("\n<info>" . $linkType . "</info>");
|
||||||
|
|
||||||
$this->output->writeln("\n<info>" . $linksName . "</info>");
|
foreach ($links as $link) {
|
||||||
|
$output->writeln($link->getTarget() . ' <comment>' . $link->getPrettyConstraint() . '</comment>');
|
||||||
foreach ($this->dump[$linksName] as $link) {
|
|
||||||
$this->output->writeln($link->getTarget() . ' <comment>' . $link->getPrettyConstraint() . '</comment>');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue