|
|
@ -15,6 +15,7 @@ namespace Composer\Command;
|
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Factory;
|
|
|
|
use Composer\Factory;
|
|
|
|
use Composer\Package\CompletePackageInterface;
|
|
|
|
use Composer\Package\CompletePackageInterface;
|
|
|
|
|
|
|
|
use Composer\Package\Version\VersionParser;
|
|
|
|
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\Input\InputOption;
|
|
|
@ -38,9 +39,9 @@ class ShowCommand extends Command
|
|
|
|
->setDefinition(array(
|
|
|
|
->setDefinition(array(
|
|
|
|
new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect'),
|
|
|
|
new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect'),
|
|
|
|
new InputArgument('version', InputArgument::OPTIONAL, 'Version to inspect'),
|
|
|
|
new InputArgument('version', InputArgument::OPTIONAL, 'Version to inspect'),
|
|
|
|
new InputOption('installed', null, InputOption::VALUE_NONE, 'List installed packages only'),
|
|
|
|
new InputOption('installed', 'i', InputOption::VALUE_NONE, 'List installed packages only'),
|
|
|
|
new InputOption('platform', null, InputOption::VALUE_NONE, 'List platform packages only'),
|
|
|
|
new InputOption('platform', 'p', InputOption::VALUE_NONE, 'List platform packages only'),
|
|
|
|
new InputOption('self', null, InputOption::VALUE_NONE, 'Show the root package information'),
|
|
|
|
new InputOption('self', 's', InputOption::VALUE_NONE, 'Show the root package information'),
|
|
|
|
))
|
|
|
|
))
|
|
|
|
->setHelp(<<<EOT
|
|
|
|
->setHelp(<<<EOT
|
|
|
|
The show command displays detailed information about a package, or
|
|
|
|
The show command displays detailed information about a package, or
|
|
|
@ -77,13 +78,14 @@ EOT
|
|
|
|
// show single package or single version
|
|
|
|
// show single package or single version
|
|
|
|
if ($input->getArgument('package') || !empty($package)) {
|
|
|
|
if ($input->getArgument('package') || !empty($package)) {
|
|
|
|
if (empty($package)) {
|
|
|
|
if (empty($package)) {
|
|
|
|
$package = $this->getPackage($input, $output, $installedRepo, $repos);
|
|
|
|
list($package, $versions) = $this->getPackage($installedRepo, $repos, $input->getArgument('package'), $input->getArgument('version'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$package) {
|
|
|
|
if (!$package) {
|
|
|
|
throw new \InvalidArgumentException('Package '.$input->getArgument('package').' not found');
|
|
|
|
throw new \InvalidArgumentException('Package '.$input->getArgument('package').' not found');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->printMeta($input, $output, $package, $installedRepo, $repos);
|
|
|
|
$this->printMeta($input, $output, $package, $versions, $installedRepo, $repos);
|
|
|
|
$this->printLinks($input, $output, $package, 'requires');
|
|
|
|
$this->printLinks($input, $output, $package, 'requires');
|
|
|
|
$this->printLinks($input, $output, $package, 'devRequires', 'requires (dev)');
|
|
|
|
$this->printLinks($input, $output, $package, 'devRequires', 'requires (dev)');
|
|
|
|
if ($package->getSuggests()) {
|
|
|
|
if ($package->getSuggests()) {
|
|
|
@ -101,7 +103,7 @@ EOT
|
|
|
|
|
|
|
|
|
|
|
|
// list packages
|
|
|
|
// list packages
|
|
|
|
$packages = array();
|
|
|
|
$packages = array();
|
|
|
|
foreach ($repos->getPackages() as $package) {
|
|
|
|
$repos->filterPackages(function ($package) use (&$packages, $platformRepo, $installedRepo) {
|
|
|
|
if ($platformRepo->hasPackage($package)) {
|
|
|
|
if ($platformRepo->hasPackage($package)) {
|
|
|
|
$type = '<info>platform</info>:';
|
|
|
|
$type = '<info>platform</info>:';
|
|
|
|
} elseif ($installedRepo->hasPackage($package)) {
|
|
|
|
} elseif ($installedRepo->hasPackage($package)) {
|
|
|
@ -109,13 +111,12 @@ EOT
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$type = '<comment>available</comment>:';
|
|
|
|
$type = '<comment>available</comment>:';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($packages[$type][$package->getName()])
|
|
|
|
if (!isset($packages[$type][$package->getName()])
|
|
|
|
&& version_compare($packages[$type][$package->getName()]->getVersion(), $package->getVersion(), '>=')
|
|
|
|
|| version_compare($packages[$type][$package->getName()]->getVersion(), $package->getVersion(), '<')
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
$packages[$type][$package->getName()] = $package;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$packages[$type][$package->getName()] = $package;
|
|
|
|
}, 'Composer\Package\CompletePackage');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (array('<info>platform</info>:' => true, '<comment>available</comment>:' => false, '<info>installed</info>:' => true) as $type => $showVersion) {
|
|
|
|
foreach (array('<info>platform</info>:' => true, '<comment>available</comment>:' => false, '<info>installed</info>:' => true) as $type => $showVersion) {
|
|
|
|
if (isset($packages[$type])) {
|
|
|
|
if (isset($packages[$type])) {
|
|
|
@ -132,44 +133,69 @@ EOT
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* finds a package by name and version if provided
|
|
|
|
* finds a package by name and version if provided
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param InputInterface $input
|
|
|
|
* @return array array(CompletePackageInterface, array of versions)
|
|
|
|
* @return CompletePackageInterface
|
|
|
|
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getPackage(InputInterface $input, OutputInterface $output, RepositoryInterface $installedRepo, RepositoryInterface $repos)
|
|
|
|
protected function getPackage(RepositoryInterface $installedRepo, RepositoryInterface $repos, $name, $version = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// we have a name and a version so we can use ::findPackage
|
|
|
|
$name = strtolower($name);
|
|
|
|
if ($input->getArgument('version')) {
|
|
|
|
if ($version) {
|
|
|
|
return $repos->findPackage($input->getArgument('package'), $input->getArgument('version'));
|
|
|
|
$parser = new VersionParser();
|
|
|
|
|
|
|
|
$version = $parser->normalize($version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// check if we have a local installation so we can grab the right package/version
|
|
|
|
$match = null;
|
|
|
|
foreach ($installedRepo->getPackages() as $package) {
|
|
|
|
$matches = array();
|
|
|
|
if ($package->getName() === $input->getArgument('package')) {
|
|
|
|
$repos->filterPackages(function ($package) use ($name, $version, &$matches) {
|
|
|
|
return $package;
|
|
|
|
if ($package->getName() === $name) {
|
|
|
|
|
|
|
|
$matches[] = $package;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'Composer\Package\CompletePackage');
|
|
|
|
|
|
|
|
|
|
|
|
// we only have a name, so search for the highest version of the given package
|
|
|
|
if (null === $version) {
|
|
|
|
$highestVersion = null;
|
|
|
|
// search for a locally installed version
|
|
|
|
foreach ($repos->findPackages($input->getArgument('package')) as $package) {
|
|
|
|
foreach ($matches as $package) {
|
|
|
|
if (null === $highestVersion || version_compare($package->getVersion(), $highestVersion->getVersion(), '>=')) {
|
|
|
|
if ($installedRepo->hasPackage($package)) {
|
|
|
|
$highestVersion = $package;
|
|
|
|
$match = $package;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$match) {
|
|
|
|
|
|
|
|
// fallback to the highest version
|
|
|
|
|
|
|
|
foreach ($matches as $package) {
|
|
|
|
|
|
|
|
if (null === $match || version_compare($package->getVersion(), $match->getVersion(), '>=')) {
|
|
|
|
|
|
|
|
$match = $package;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// select the specified version
|
|
|
|
|
|
|
|
foreach ($matches as $package) {
|
|
|
|
|
|
|
|
if ($package->getVersion() === $version) {
|
|
|
|
|
|
|
|
$match = $package;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// build versions array
|
|
|
|
|
|
|
|
$versions = array();
|
|
|
|
|
|
|
|
foreach ($matches as $package) {
|
|
|
|
|
|
|
|
$versions[$package->getPrettyVersion()] = $package->getVersion();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $highestVersion;
|
|
|
|
return array($match, $versions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* prints package meta data
|
|
|
|
* prints package meta data
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function printMeta(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $repos)
|
|
|
|
protected function printMeta(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, RepositoryInterface $repos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$output->writeln('<info>name</info> : ' . $package->getPrettyName());
|
|
|
|
$output->writeln('<info>name</info> : ' . $package->getPrettyName());
|
|
|
|
$output->writeln('<info>descrip.</info> : ' . $package->getDescription());
|
|
|
|
$output->writeln('<info>descrip.</info> : ' . $package->getDescription());
|
|
|
|
$output->writeln('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
|
|
|
|
$output->writeln('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
|
|
|
|
$this->printVersions($input, $output, $package, $installedRepo, $repos);
|
|
|
|
$this->printVersions($input, $output, $package, $versions, $installedRepo, $repos);
|
|
|
|
$output->writeln('<info>type</info> : ' . $package->getType());
|
|
|
|
$output->writeln('<info>type</info> : ' . $package->getType());
|
|
|
|
$output->writeln('<info>license</info> : ' . implode(', ', $package->getLicense()));
|
|
|
|
$output->writeln('<info>license</info> : ' . implode(', ', $package->getLicense()));
|
|
|
|
$output->writeln('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
|
|
|
|
$output->writeln('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
|
|
|
@ -206,7 +232,7 @@ 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, OutputInterface $output, CompletePackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $repos)
|
|
|
|
protected function printVersions(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, RepositoryInterface $repos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ($input->getArgument('version')) {
|
|
|
|
if ($input->getArgument('version')) {
|
|
|
|
$output->writeln('<info>version</info> : ' . $package->getPrettyVersion());
|
|
|
|
$output->writeln('<info>version</info> : ' . $package->getPrettyVersion());
|
|
|
@ -214,14 +240,7 @@ EOT
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$versions = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($repos->findPackages($package->getName()) as $version) {
|
|
|
|
|
|
|
|
$versions[$version->getPrettyVersion()] = $version->getVersion();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uasort($versions, 'version_compare');
|
|
|
|
uasort($versions, 'version_compare');
|
|
|
|
|
|
|
|
|
|
|
|
$versions = implode(', ', array_keys(array_reverse($versions)));
|
|
|
|
$versions = implode(', ', array_keys(array_reverse($versions)));
|
|
|
|
|
|
|
|
|
|
|
|
// highlight installed version
|
|
|
|
// highlight installed version
|
|
|
|