فهرست منبع

Merge pull request #5552 from fvdb/add-minor-only-option

Added minor-only option to show command to only show packages with minor updates
Jordi Boggiano 8 سال پیش
والد
کامیت
f3af3ede40
2فایلهای تغییر یافته به همراه11 افزوده شده و 2 حذف شده
  1. 2 0
      doc/03-cli.md
  2. 9 2
      src/Composer/Command/ShowCommand.php

+ 2 - 0
doc/03-cli.md

@@ -333,6 +333,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-compatible updates.
 * **--direct (-D):** Restricts the list of packages to your direct dependencies.
 
 ## outdated
@@ -352,6 +353,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-compatible updates.
 
 ## browse / home
 

+ 9 - 2
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 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(<<<EOT
@@ -259,6 +260,7 @@ EOT
 
         $showAllTypes = $input->getOption('all');
         $showLatest = $input->getOption('latest');
+        $showMinorOnly = $input->getOption('minor-only');
         $indent = $showAllTypes ? '  ' : '';
         $latestPackages = array();
         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()));
                             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);
     }