From 7d52bd6ed57591c497d12d2795589fc76078ce45 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Mon, 28 Nov 2016 11:54:35 +0100 Subject: [PATCH] Non-zero status code when there are outdated packages (fixes #5901) --- src/Composer/Command/OutdatedCommand.php | 4 ++++ src/Composer/Command/ShowCommand.php | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/Composer/Command/OutdatedCommand.php b/src/Composer/Command/OutdatedCommand.php index b3cf566df..6c535e150 100644 --- a/src/Composer/Command/OutdatedCommand.php +++ b/src/Composer/Command/OutdatedCommand.php @@ -33,6 +33,7 @@ class OutdatedCommand extends ShowCommand new InputOption('outdated', 'o', InputOption::VALUE_NONE, 'Show only packages that are outdated (this is the default, but present here for compat with `show`'), new InputOption('all', 'a', InputOption::VALUE_NONE, 'Show all installed packages with their latest versions'), 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'), )) ->setHelp(<<getArgument('package')) { $args['package'] = $input->getArgument('package'); } + if ($input->getOption('strict')) { + $args['--strict'] = true; + } $input = new ArrayInput($args); diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 6555c8be4..a6826d641 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -73,6 +73,7 @@ class ShowCommand extends BaseCommand 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'), + new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code when there are outdated packages'), )) ->setHelp(<<getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width); $writeLatest = $writeVersion && $showLatest && ($nameLength + $versionLength + $latestLength + 3 <= $width); $writeDescription = !$input->getOption('name-only') && !$input->getOption('path') && ($nameLength + $versionLength + $latestLength + 24 <= $width); + $hasOutdatedPackages = false; foreach ($packages[$type] as $package) { if (is_object($package)) { $latestPackackage = null; @@ -318,6 +320,8 @@ EOT } if ($input->getOption('outdated') && $latestPackackage && $latestPackackage->getFullPrettyVersion() === $package->getFullPrettyVersion() && !$latestPackackage->isAbandoned()) { continue; + } elseif ($input->getOption('outdated')) { + $hasOutdatedPackages = true; } $io->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false); @@ -372,6 +376,9 @@ EOT if ($showAllTypes) { $io->write(''); } + if ($input->getOption('strict') && $hasOutdatedPackages) { + return 1; + } } } }