1
0
Fork 0

Support for ignoring packages in `outdated` command (#7682)

* Support for ignoring packages in `outdated` command. Fixes #7656
pull/7641/head^2
Grzegorz Korba 2018-10-31 17:18:54 +01:00 committed by Jordi Boggiano
parent 148e503b31
commit 0ee0138bed
2 changed files with 11 additions and 1 deletions

View File

@ -36,6 +36,7 @@ class OutdatedCommand extends ShowCommand
new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code when there are outdated packages'), new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code when there are outdated packages'),
new InputOption('minor-only', 'm', InputOption::VALUE_NONE, 'Show only packages that have minor SemVer-compatible updates. Use with the --outdated option.'), new InputOption('minor-only', 'm', InputOption::VALUE_NONE, 'Show only packages that have minor SemVer-compatible updates. Use with the --outdated option.'),
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text'), new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text'),
new InputOption('ignore', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore specified package(s). Use it with the --outdated option if you don\'t want to be informed about new versions of some packages.'),
)) ))
->setHelp( ->setHelp(
<<<EOT <<<EOT
@ -77,6 +78,7 @@ EOT
$args['--minor-only'] = true; $args['--minor-only'] = true;
} }
$args['--format'] = $input->getOption('format'); $args['--format'] = $input->getOption('format');
$args['--ignore'] = $input->getOption('ignore');
$input = new ArrayInput($args); $input = new ArrayInput($args);

View File

@ -74,6 +74,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('ignore', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore specified package(s). Use it with the --outdated option if you don\'t want to be informed about new versions of some packages.'),
new InputOption('minor-only', 'm', InputOption::VALUE_NONE, 'Show only packages that have minor SemVer-compatible updates. Use with the --outdated option.'), 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'), new InputOption('direct', 'D', InputOption::VALUE_NONE, 'Shows only packages that are directly required by the root package'),
new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code when there are outdated packages'), new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code when there are outdated packages'),
@ -105,6 +106,8 @@ EOT
if ($input->getOption('outdated')) { if ($input->getOption('outdated')) {
$input->setOption('latest', true); $input->setOption('latest', true);
} elseif ($input->getOption('ignore')) {
$io->writeError('<warning>You are using the option "ignore" for action other than "outdated", it will be ignored.</warning>');
} }
if ($input->getOption('direct') && ($input->getOption('all') || $input->getOption('available') || $input->getOption('platform'))) { if ($input->getOption('direct') && ($input->getOption('all') || $input->getOption('available') || $input->getOption('platform'))) {
@ -333,6 +336,7 @@ EOT
$showAllTypes = $input->getOption('all'); $showAllTypes = $input->getOption('all');
$showLatest = $input->getOption('latest'); $showLatest = $input->getOption('latest');
$showMinorOnly = $input->getOption('minor-only'); $showMinorOnly = $input->getOption('minor-only');
$ignoredPackages = array_map('strtolower', $input->getOption('ignore'));
$indent = $showAllTypes ? ' ' : ''; $indent = $showAllTypes ? ' ' : '';
$latestPackages = array(); $latestPackages = array();
$exitCode = 0; $exitCode = 0;
@ -372,7 +376,11 @@ EOT
if ($showLatest && isset($latestPackages[$package->getPrettyName()])) { if ($showLatest && isset($latestPackages[$package->getPrettyName()])) {
$latestPackage = $latestPackages[$package->getPrettyName()]; $latestPackage = $latestPackages[$package->getPrettyName()];
} }
if ($input->getOption('outdated') && $latestPackage && $latestPackage->getFullPrettyVersion() === $package->getFullPrettyVersion() && !$latestPackage->isAbandoned()) {
// Determine if Composer is checking outdated dependencies and if current package should trigger non-default exit code
$packageIsUpToDate = $latestPackage && $latestPackage->getFullPrettyVersion() === $package->getFullPrettyVersion() && !$latestPackage->isAbandoned();
$packageIsIgnored = \in_array($package->getPrettyName(), $ignoredPackages, true);
if ($input->getOption('outdated') && ($packageIsUpToDate || $packageIsIgnored)) {
continue; continue;
} elseif ($input->getOption('outdated') || $input->getOption('strict')) { } elseif ($input->getOption('outdated') || $input->getOption('strict')) {
$hasOutdatedPackages = true; $hasOutdatedPackages = true;