Merge remote-tracking branch 'barryvdh/show-outdated'
commit
9206c646a2
|
@ -16,6 +16,7 @@ use Composer\DependencyResolver\Pool;
|
||||||
use Composer\DependencyResolver\DefaultPolicy;
|
use Composer\DependencyResolver\DefaultPolicy;
|
||||||
use Composer\Package\CompletePackageInterface;
|
use Composer\Package\CompletePackageInterface;
|
||||||
use Composer\Package\Version\VersionParser;
|
use Composer\Package\Version\VersionParser;
|
||||||
|
use Composer\Package\Version\VersionSelector;
|
||||||
use Composer\Plugin\CommandEvent;
|
use Composer\Plugin\CommandEvent;
|
||||||
use Composer\Plugin\PluginEvents;
|
use Composer\Plugin\PluginEvents;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
|
@ -45,6 +46,12 @@ class ShowCommand extends BaseCommand
|
||||||
protected $versionParser;
|
protected $versionParser;
|
||||||
protected $colors;
|
protected $colors;
|
||||||
|
|
||||||
|
/** @var CompositeRepository */
|
||||||
|
protected $repos;
|
||||||
|
|
||||||
|
/** @var Pool */
|
||||||
|
private $pool;
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -62,6 +69,7 @@ class ShowCommand extends BaseCommand
|
||||||
new InputOption('name-only', 'N', InputOption::VALUE_NONE, 'List package names only'),
|
new InputOption('name-only', 'N', InputOption::VALUE_NONE, 'List package names only'),
|
||||||
new InputOption('path', 'P', InputOption::VALUE_NONE, 'Show package paths'),
|
new InputOption('path', 'P', InputOption::VALUE_NONE, 'Show package paths'),
|
||||||
new InputOption('tree', 't', InputOption::VALUE_NONE, 'List the dependencies as a tree'),
|
new InputOption('tree', 't', InputOption::VALUE_NONE, 'List the dependencies as a tree'),
|
||||||
|
new InputOption('latest', 'l', InputOption::VALUE_NONE, 'Show the latest version'),
|
||||||
))
|
))
|
||||||
->setHelp(<<<EOT
|
->setHelp(<<<EOT
|
||||||
The show command displays detailed information about a package, or
|
The show command displays detailed information about a package, or
|
||||||
|
@ -148,7 +156,11 @@ EOT
|
||||||
if ($input->getOption('tree')) {
|
if ($input->getOption('tree')) {
|
||||||
$this->displayPackageTree($package, $installedRepo, $repos);
|
$this->displayPackageTree($package, $installedRepo, $repos);
|
||||||
} else {
|
} else {
|
||||||
$this->printMeta($package, $versions, $installedRepo);
|
$latestVersion = null;
|
||||||
|
if ($input->getOption('latest')) {
|
||||||
|
$latestVersion = $this->findBestVersionForPackage($package->getName(), null);
|
||||||
|
}
|
||||||
|
$this->printMeta($package, $versions, $installedRepo, $latestVersion);
|
||||||
$this->printLinks($package, 'requires');
|
$this->printLinks($package, 'requires');
|
||||||
$this->printLinks($package, 'devRequires', 'requires (dev)');
|
$this->printLinks($package, 'devRequires', 'requires (dev)');
|
||||||
if ($package->getSuggests()) {
|
if ($package->getSuggests()) {
|
||||||
|
@ -226,6 +238,7 @@ EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
$showAllTypes = $input->getOption('all');
|
$showAllTypes = $input->getOption('all');
|
||||||
|
$showLatest = $input->getOption('latest');
|
||||||
$indent = $showAllTypes ? ' ' : '';
|
$indent = $showAllTypes ? ' ' : '';
|
||||||
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])) {
|
||||||
|
@ -234,7 +247,7 @@ EOT
|
||||||
}
|
}
|
||||||
ksort($packages[$type]);
|
ksort($packages[$type]);
|
||||||
|
|
||||||
$nameLength = $versionLength = 0;
|
$nameLength = $versionLength = $latestLength = 0;
|
||||||
foreach ($packages[$type] as $package) {
|
foreach ($packages[$type] as $package) {
|
||||||
if (is_object($package)) {
|
if (is_object($package)) {
|
||||||
$nameLength = max($nameLength, strlen($package->getPrettyName()));
|
$nameLength = max($nameLength, strlen($package->getPrettyName()));
|
||||||
|
@ -258,9 +271,11 @@ EOT
|
||||||
$input->setOption('path', false);
|
$input->setOption('path', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$latestLength = $versionLength;
|
||||||
$writePath = !$input->getOption('name-only') && $input->getOption('path');
|
$writePath = !$input->getOption('name-only') && $input->getOption('path');
|
||||||
$writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width);
|
$writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width);
|
||||||
$writeDescription = !$input->getOption('name-only') && !$input->getOption('path') && ($nameLength + ($showVersion ? $versionLength : 0) + 24 <= $width);
|
$writeLatest = !$input->getOption('name-only') && !$input->getOption('path') && $showLatest && ($nameLength + ($showVersion ? $versionLength : 0) + $latestLength + 3 <= $width);
|
||||||
|
$writeDescription = !$input->getOption('name-only') && !$input->getOption('path') && ($nameLength + ($showVersion ? $versionLength : 0) + ($showLatest ? $latestLength : 0) + 24 <= $width);
|
||||||
foreach ($packages[$type] as $package) {
|
foreach ($packages[$type] as $package) {
|
||||||
if (is_object($package)) {
|
if (is_object($package)) {
|
||||||
$io->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false);
|
$io->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false);
|
||||||
|
@ -269,9 +284,15 @@ EOT
|
||||||
$io->write(' ' . str_pad($package->getFullPrettyVersion(), $versionLength, ' '), false);
|
$io->write(' ' . str_pad($package->getFullPrettyVersion(), $versionLength, ' '), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($writeLatest) {
|
||||||
|
$latestVersion = $this->findBestVersionForPackage($package->getName());
|
||||||
|
$type = $latestVersion == $package->getFullPrettyVersion() ? 'info' : 'comment';
|
||||||
|
$io->write(' <'.$type.'>' . str_pad($latestVersion, $latestLength, ' ') . '</'.$type.'>', false);
|
||||||
|
}
|
||||||
|
|
||||||
if ($writeDescription) {
|
if ($writeDescription) {
|
||||||
$description = strtok($package->getDescription(), "\r\n");
|
$description = strtok($package->getDescription(), "\r\n");
|
||||||
$remaining = $width - $nameLength - $versionLength - 4;
|
$remaining = $width - $nameLength - $versionLength - ($writeLatest ? $latestLength : 0) - 4;
|
||||||
if (strlen($description) > $remaining) {
|
if (strlen($description) > $remaining) {
|
||||||
$description = substr($description, 0, $remaining - 3) . '...';
|
$description = substr($description, 0, $remaining - 3) . '...';
|
||||||
}
|
}
|
||||||
|
@ -347,13 +368,16 @@ EOT
|
||||||
* @param array $versions
|
* @param array $versions
|
||||||
* @param RepositoryInterface $installedRepo
|
* @param RepositoryInterface $installedRepo
|
||||||
*/
|
*/
|
||||||
protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo)
|
protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, $latestVersion = null)
|
||||||
{
|
{
|
||||||
$io = $this->getIO();
|
$io = $this->getIO();
|
||||||
$io->write('<info>name</info> : ' . $package->getPrettyName());
|
$io->write('<info>name</info> : ' . $package->getPrettyName());
|
||||||
$io->write('<info>descrip.</info> : ' . $package->getDescription());
|
$io->write('<info>descrip.</info> : ' . $package->getDescription());
|
||||||
$io->write('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
|
$io->write('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
|
||||||
$this->printVersions($package, $versions, $installedRepo);
|
$this->printVersions($package, $versions, $installedRepo);
|
||||||
|
if ($latestVersion) {
|
||||||
|
$io->write('<info>latest</info> : ' . $latestVersion);
|
||||||
|
}
|
||||||
$io->write('<info>type</info> : ' . $package->getType());
|
$io->write('<info>type</info> : ' . $package->getType());
|
||||||
$this->printLicenses($package);
|
$this->printLicenses($package);
|
||||||
$io->write('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
|
$io->write('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
|
||||||
|
@ -589,4 +613,49 @@ EOT
|
||||||
|
|
||||||
$io->write($line);
|
$io->write($line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a package name, this determines the best version to use in the require key.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
private function findBestVersionForPackage($name)
|
||||||
|
{
|
||||||
|
// find the latest version allowed in this pool
|
||||||
|
$versionSelector = new VersionSelector($this->getPool());
|
||||||
|
$package = $versionSelector->findBestCandidate($name);
|
||||||
|
|
||||||
|
if ($package) {
|
||||||
|
return $package->getPrettyVersion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRepos()
|
||||||
|
{
|
||||||
|
if (!$this->repos) {
|
||||||
|
$this->repos = new CompositeRepository(array_merge(
|
||||||
|
array(new PlatformRepository),
|
||||||
|
RepositoryFactory::defaultRepos($this->getIO())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->repos;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getPool()
|
||||||
|
{
|
||||||
|
if (!$this->pool) {
|
||||||
|
$this->pool = new Pool($this->getMinimumStability());
|
||||||
|
$this->pool->addRepository($this->getRepos());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getMinimumStability()
|
||||||
|
{
|
||||||
|
return 'stable';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue