Merge pull request #5907 from Rudloff/feature/status-code

Non-zero status code when there are outdated packages (fixes #5901)
main
Jordi Boggiano 8 years ago committed by GitHub
commit 0f276e3890

@ -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('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('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('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(<<<EOT ->setHelp(<<<EOT
The outdated command is just a proxy for `composer show -l` The outdated command is just a proxy for `composer show -l`
@ -66,6 +67,9 @@ EOT
if ($input->getArgument('package')) { if ($input->getArgument('package')) {
$args['package'] = $input->getArgument('package'); $args['package'] = $input->getArgument('package');
} }
if ($input->getOption('strict')) {
$args['--strict'] = true;
}
$input = new ArrayInput($args); $input = new ArrayInput($args);

@ -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('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('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'),
)) ))
->setHelp(<<<EOT ->setHelp(<<<EOT
The show command displays detailed information about a package, or The show command displays detailed information about a package, or
@ -310,6 +311,7 @@ EOT
$writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width); $writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width);
$writeLatest = $writeVersion && $showLatest && ($nameLength + $versionLength + $latestLength + 3 <= $width); $writeLatest = $writeVersion && $showLatest && ($nameLength + $versionLength + $latestLength + 3 <= $width);
$writeDescription = !$input->getOption('name-only') && !$input->getOption('path') && ($nameLength + $versionLength + $latestLength + 24 <= $width); $writeDescription = !$input->getOption('name-only') && !$input->getOption('path') && ($nameLength + $versionLength + $latestLength + 24 <= $width);
$hasOutdatedPackages = false;
foreach ($packages[$type] as $package) { foreach ($packages[$type] as $package) {
if (is_object($package)) { if (is_object($package)) {
$latestPackackage = null; $latestPackackage = null;
@ -318,6 +320,8 @@ EOT
} }
if ($input->getOption('outdated') && $latestPackackage && $latestPackackage->getFullPrettyVersion() === $package->getFullPrettyVersion() && !$latestPackackage->isAbandoned()) { if ($input->getOption('outdated') && $latestPackackage && $latestPackackage->getFullPrettyVersion() === $package->getFullPrettyVersion() && !$latestPackackage->isAbandoned()) {
continue; continue;
} elseif ($input->getOption('outdated')) {
$hasOutdatedPackages = true;
} }
$io->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false); $io->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false);
@ -372,6 +376,9 @@ EOT
if ($showAllTypes) { if ($showAllTypes) {
$io->write(''); $io->write('');
} }
if ($input->getOption('strict') && $hasOutdatedPackages) {
return 1;
}
} }
} }
} }

Loading…
Cancel
Save