1
0
Fork 0

Added minor-only option to show command to only show packages with minor updates

pull/5552/head
Frank van den Brink 2016-08-26 10:34:09 +02:00
parent 79d1a050e3
commit cb7377d2cb
No known key found for this signature in database
GPG Key ID: F6CBCF6CB657D94D
1 changed files with 9 additions and 2 deletions

View File

@ -71,6 +71,7 @@ class ShowCommand extends BaseCommand
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'), new InputOption('latest', 'l', InputOption::VALUE_NONE, 'Show the latest version'),
new InputOption('outdated', 'o', InputOption::VALUE_NONE, 'Show the latest version but only for packages that are outdated'), new InputOption('outdated', 'o', InputOption::VALUE_NONE, 'Show the latest version but only for packages that are outdated'),
new InputOption('minor-only', 'm', InputOption::VALUE_NONE, 'Show the latest version but only for packages that have minor SemVer-compatible updates'),
new InputOption('direct', 'D', InputOption::VALUE_NONE, 'Shows only packages that are directly required by the root package'), new InputOption('direct', 'D', InputOption::VALUE_NONE, 'Shows only packages that are directly required by the root package'),
)) ))
->setHelp(<<<EOT ->setHelp(<<<EOT
@ -259,6 +260,7 @@ EOT
$showAllTypes = $input->getOption('all'); $showAllTypes = $input->getOption('all');
$showLatest = $input->getOption('latest'); $showLatest = $input->getOption('latest');
$showMinorOnly = $input->getOption('minor-only');
$indent = $showAllTypes ? ' ' : ''; $indent = $showAllTypes ? ' ' : '';
$latestPackages = array(); $latestPackages = array();
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) {
@ -276,7 +278,7 @@ EOT
$versionLength = max($versionLength, strlen($package->getFullPrettyVersion())); $versionLength = max($versionLength, strlen($package->getFullPrettyVersion()));
if ($showLatest) { if ($showLatest) {
$latestPackage = $this->findLatestPackage($package, $composer, $phpVersion); $latestPackage = $this->findLatestPackage($package, $composer, $phpVersion, $showMinorOnly);
if ($latestPackage === false) { if ($latestPackage === false) {
continue; continue;
} }
@ -711,10 +713,11 @@ EOT
* @param PackageInterface $package * @param PackageInterface $package
* @param Composer $composer * @param Composer $composer
* @param string $phpVersion * @param string $phpVersion
* @param bool $minorOnly
* *
* @return PackageInterface|null * @return PackageInterface|null
*/ */
private function findLatestPackage(PackageInterface $package, Composer $composer, $phpVersion) private function findLatestPackage(PackageInterface $package, Composer $composer, $phpVersion, $minorOnly = false)
{ {
// find the latest version allowed in this pool // find the latest version allowed in this pool
$name = $package->getName(); $name = $package->getName();
@ -735,6 +738,10 @@ EOT
$targetVersion = $package->getVersion(); $targetVersion = $package->getVersion();
} }
if ($targetVersion === null && $minorOnly) {
$targetVersion = '^' . $package->getVersion();
}
return $versionSelector->findBestCandidate($name, $targetVersion, $phpVersion, $bestStability); return $versionSelector->findBestCandidate($name, $targetVersion, $phpVersion, $bestStability);
} }