From 4b0e40d482f11647b49889a24c1ea20948f7707c Mon Sep 17 00:00:00 2001 From: Frank van den Brink Date: Tue, 26 Jul 2016 09:39:56 +0200 Subject: [PATCH 1/6] Added minor-only option to only show packages with minor updates --- src/Composer/Command/ShowCommand.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index b00348f08..8fdd63097 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -71,6 +71,7 @@ class ShowCommand extends BaseCommand 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('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 only packages which have minor updates. Use in combination with --outdated'), new InputOption('direct', 'D', InputOption::VALUE_NONE, 'Shows only packages that are directly required by the root package'), )) ->setHelp(<<getPrettyName()])) { $latestPackackage = $latestPackages[$package->getPrettyName()]; } + + if ($input->getOption('outdated') && $input->getOption('minor-only') && $latestPackackage && (!$this->isImmediateSemverCompliantUpgradeNeeded($package, $latestPackackage) || $latestPackackage->isAbandoned())) { + continue; + } + if ($input->getOption('outdated') && $latestPackackage && $latestPackackage->getFullPrettyVersion() === $package->getFullPrettyVersion() && !$latestPackackage->isAbandoned()) { continue; } @@ -390,11 +396,7 @@ EOT return 'info'; } - $constraint = $package->getVersion(); - if (0 !== strpos($constraint, 'dev-')) { - $constraint = '^'.$constraint; - } - if ($latestPackage->getVersion() && Semver::satisfies($latestPackage->getVersion(), $constraint)) { + if ($this->isImmediateSemverCompliantUpgradeNeeded($package, $latestPackage)) { // print red as it needs an immediate semver-compliant upgrade return 'highlight'; } @@ -403,6 +405,16 @@ EOT return 'comment'; } + protected function isImmediateSemverCompliantUpgradeNeeded(PackageInterface $package, PackageInterface $latestPackage) + { + $constraint = $package->getVersion(); + if (0 !== strpos($constraint, 'dev-')) { + $constraint = '^'.$constraint; + } + + return $latestPackage->getVersion() && Semver::satisfies($latestPackage->getVersion(), $constraint); + } + /** * finds a package by name and version if provided * From 28851ecdca613939bf53146484ee1461f95efa16 Mon Sep 17 00:00:00 2001 From: Frank van den Brink Date: Fri, 26 Aug 2016 10:32:57 +0200 Subject: [PATCH 2/6] Revert "Added minor-only option to only show packages with minor updates" This reverts commit 4b0e40d482f11647b49889a24c1ea20948f7707c. --- src/Composer/Command/ShowCommand.php | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 8fdd63097..b00348f08 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -71,7 +71,6 @@ class ShowCommand extends BaseCommand 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('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 only packages which have minor updates. Use in combination with --outdated'), new InputOption('direct', 'D', InputOption::VALUE_NONE, 'Shows only packages that are directly required by the root package'), )) ->setHelp(<<getPrettyName()])) { $latestPackackage = $latestPackages[$package->getPrettyName()]; } - - if ($input->getOption('outdated') && $input->getOption('minor-only') && $latestPackackage && (!$this->isImmediateSemverCompliantUpgradeNeeded($package, $latestPackackage) || $latestPackackage->isAbandoned())) { - continue; - } - if ($input->getOption('outdated') && $latestPackackage && $latestPackackage->getFullPrettyVersion() === $package->getFullPrettyVersion() && !$latestPackackage->isAbandoned()) { continue; } @@ -396,7 +390,11 @@ EOT return 'info'; } - if ($this->isImmediateSemverCompliantUpgradeNeeded($package, $latestPackage)) { + $constraint = $package->getVersion(); + if (0 !== strpos($constraint, 'dev-')) { + $constraint = '^'.$constraint; + } + if ($latestPackage->getVersion() && Semver::satisfies($latestPackage->getVersion(), $constraint)) { // print red as it needs an immediate semver-compliant upgrade return 'highlight'; } @@ -405,16 +403,6 @@ EOT return 'comment'; } - protected function isImmediateSemverCompliantUpgradeNeeded(PackageInterface $package, PackageInterface $latestPackage) - { - $constraint = $package->getVersion(); - if (0 !== strpos($constraint, 'dev-')) { - $constraint = '^'.$constraint; - } - - return $latestPackage->getVersion() && Semver::satisfies($latestPackage->getVersion(), $constraint); - } - /** * finds a package by name and version if provided * From cb7377d2cb71a7c8f4038366c0ba9e00c1d85f42 Mon Sep 17 00:00:00 2001 From: Frank van den Brink Date: Fri, 26 Aug 2016 10:34:09 +0200 Subject: [PATCH 3/6] Added minor-only option to show command to only show packages with minor updates --- src/Composer/Command/ShowCommand.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index b00348f08..cb364b953 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -71,6 +71,7 @@ class ShowCommand extends BaseCommand 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('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'), )) ->setHelp(<<getOption('all'); $showLatest = $input->getOption('latest'); + $showMinorOnly = $input->getOption('minor-only'); $indent = $showAllTypes ? ' ' : ''; $latestPackages = array(); foreach (array('platform:' => true, 'available:' => false, 'installed:' => true) as $type => $showVersion) { @@ -276,7 +278,7 @@ EOT $versionLength = max($versionLength, strlen($package->getFullPrettyVersion())); if ($showLatest) { - $latestPackage = $this->findLatestPackage($package, $composer, $phpVersion); + $latestPackage = $this->findLatestPackage($package, $composer, $phpVersion, $showMinorOnly); if ($latestPackage === false) { continue; } @@ -711,10 +713,11 @@ EOT * @param PackageInterface $package * @param Composer $composer * @param string $phpVersion + * @param bool $minorOnly * * @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 $name = $package->getName(); @@ -735,6 +738,10 @@ EOT $targetVersion = $package->getVersion(); } + if ($targetVersion === null && $minorOnly) { + $targetVersion = '^' . $package->getVersion(); + } + return $versionSelector->findBestCandidate($name, $targetVersion, $phpVersion, $bestStability); } From e60a7216c6a054ba08d4d8bdd6b9c8c241894d2e Mon Sep 17 00:00:00 2001 From: Frank van den Brink Date: Fri, 26 Aug 2016 10:47:10 +0200 Subject: [PATCH 4/6] Clarified minor-only option description --- src/Composer/Command/ShowCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index cb364b953..a0a010f54 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -71,7 +71,7 @@ class ShowCommand extends BaseCommand 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('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('minor-only', 'm', InputOption::VALUE_NONE, 'Show only packages that have minor SemVer-compatible updates. Use with the --outdated option.'), new InputOption('direct', 'D', InputOption::VALUE_NONE, 'Shows only packages that are directly required by the root package'), )) ->setHelp(<< Date: Fri, 26 Aug 2016 11:12:27 +0200 Subject: [PATCH 5/6] Added --minor-only option to documentation --- doc/03-cli.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/03-cli.md b/doc/03-cli.md index 5beb2fe6e..896179dad 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -332,6 +332,7 @@ php composer.phar show monolog/monolog 1.0.2 * **--name-only (-N):** List package names only. * **--path (-P):** List package paths. * **--outdated (-o):** Implies --latest, but this lists *only* packages that have a newer version available. +* **--minor-only (-m):** Use with --latest. Only shows packages that have minor SemVer-compatiable updates. * **--direct (-D):** Restricts the list of packages to your direct dependencies. ## outdated @@ -351,6 +352,7 @@ The color coding is as such: * **--all (-a):** Show all packages, not just outdated (alias for `composer show -l`). * **--direct (-D):** Restricts the list of packages to your direct dependencies. +* **--minor-only (-m):** Only shows packages that have minor SemVer-compatiable updates. ## browse / home From d5dbe5743a57a18908acf578629c4a996379f342 Mon Sep 17 00:00:00 2001 From: Frank van den Brink Date: Fri, 26 Aug 2016 11:14:08 +0200 Subject: [PATCH 6/6] Fixed typo in --minor-only option documentation --- doc/03-cli.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/03-cli.md b/doc/03-cli.md index 896179dad..2719959bc 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -332,7 +332,7 @@ php composer.phar show monolog/monolog 1.0.2 * **--name-only (-N):** List package names only. * **--path (-P):** List package paths. * **--outdated (-o):** Implies --latest, but this lists *only* packages that have a newer version available. -* **--minor-only (-m):** Use with --latest. Only shows packages that have minor SemVer-compatiable updates. +* **--minor-only (-m):** Use with --latest. Only shows packages that have minor SemVer-compatible updates. * **--direct (-D):** Restricts the list of packages to your direct dependencies. ## outdated @@ -352,7 +352,7 @@ The color coding is as such: * **--all (-a):** Show all packages, not just outdated (alias for `composer show -l`). * **--direct (-D):** Restricts the list of packages to your direct dependencies. -* **--minor-only (-m):** Only shows packages that have minor SemVer-compatiable updates. +* **--minor-only (-m):** Only shows packages that have minor SemVer-compatible updates. ## browse / home