#8945 Add "--no-dev" to outdated/show commands

main
Thomas Lamy 4 years ago
parent d4e5135d0f
commit caa5545478

@ -37,6 +37,7 @@ class OutdatedCommand extends ShowCommand
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('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('no-dev', null, InputOption::VALUE_NONE, 'Disables search in require-dev packages.'),
))
->setHelp(
<<<EOT
@ -77,6 +78,9 @@ EOT
if ($input->getOption('minor-only')) {
$args['--minor-only'] = true;
}
if ($input->getOption('no-dev')) {
$args['--no-dev'] = true;
}
$args['--format'] = $input->getOption('format');
$args['--ignore'] = $input->getOption('ignore');

@ -81,6 +81,7 @@ class ShowCommand extends BaseCommand
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('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text'),
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables search in require-dev packages.'),
))
->setHelp(
<<<EOT
@ -196,6 +197,15 @@ EOT
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
} else {
$repos = $installedRepo = new InstalledRepository(array($this->getComposer()->getRepositoryManager()->getLocalRepository()));
$root = $composer->getPackage();
$repo = $composer->getRepositoryManager()->getLocalRepository();
if ($input->getOption('no-dev')) {
$packages = $this->filterRequiredPackages($repo, $root);
} else {
$packages = $this->appendPackages($repo->getPackages(), array());
}
$packageNames = array_keys($packages);
$rootPkg = $this->getComposer()->getPackage();
if (!$installedRepo->getPackages() && ($rootPkg->getRequires() || $rootPkg->getDevRequires())) {
$io->writeError('<warning>No dependencies installed. Try running composer install or update.</warning>');
@ -348,7 +358,13 @@ EOT
}
}
} else {
foreach ($repo->getPackages() as $package) {
$root = $composer->getPackage();
if ($input->getOption('no-dev')) {
$packageList = $this->filterRequiredPackages($repo, $root);
} else {
$packageList = $this->appendPackages($repo->getPackages(), array());
}
foreach ($packageList as $package) {
if (!isset($packages[$type][$package->getName()])
|| !is_object($packages[$type][$package->getName()])
|| version_compare($packages[$type][$package->getName()]->getVersion(), $package->getVersion(), '<')
@ -1223,4 +1239,48 @@ EOT
return $this->repositorySet;
}
/**
* Find package requires and child requires
*
* @param RepositoryInterface $repo
* @param PackageInterface $package
* @param array $bucket
* @return array
*/
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array())
{
$requires = array_keys($package->getRequires());
$packageListNames = array_keys($bucket);
$packages = array_filter(
$repo->getPackages(),
function ($package) use ($requires, $packageListNames) {
return in_array($package->getName(), $requires, true) && ! in_array($package->getName(), $packageListNames, true);
}
);
$bucket = $this->appendPackages($packages, $bucket);
foreach ($packages as $requiredPackage) {
$bucket = $this->filterRequiredPackages($repo, $requiredPackage, $bucket);
}
return $bucket;
}
/**
* Adds packages to the package list
*
* @param array $packages the list of packages to add
* @param array $bucket the list to add packages to
* @return array
*/
public function appendPackages(array $packages, array $bucket)
{
foreach ($packages as $package) {
$bucket[$package->getName()] = $package;
}
return $bucket;
}
}

Loading…
Cancel
Save