1
0
Fork 0

Merge pull request #8836 from kbacia7/master

close #8784, Added --locked option to composer show command. Displaying locked packages with --all option
pull/8852/head
Jordi Boggiano 2020-04-28 08:54:16 +02:00 committed by GitHub
commit a63913c245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -360,6 +360,7 @@ php composer.phar show monolog/monolog 1.0.2
* **--all :** List all packages available in all your repositories.
* **--installed (-i):** List the packages that are installed (this is enabled by default, and deprecated).
* **--locked:** List the locked packages from composer.lock.
* **--platform (-p):** List only platform packages (php & extensions).
* **--available (-a):** List available packages only.
* **--self (-s):** List the root package info.

View File

@ -66,6 +66,7 @@ class ShowCommand extends BaseCommand
new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect. Or a name including a wildcard (*) to filter lists of packages instead.'),
new InputArgument('version', InputArgument::OPTIONAL, 'Version or version constraint to inspect'),
new InputOption('all', null, InputOption::VALUE_NONE, 'List all packages'),
new InputOption('locked', null, InputOption::VALUE_NONE, 'List all locked packages'),
new InputOption('installed', 'i', InputOption::VALUE_NONE, 'List installed packages only (enabled by default, only present for BC).'),
new InputOption('platform', 'p', InputOption::VALUE_NONE, 'List platform packages only'),
new InputOption('available', 'a', InputOption::VALUE_NONE, 'List available packages only'),
@ -149,6 +150,7 @@ EOT
$platformOverrides = $composer->getConfig()->get('platform') ?: array();
}
$platformRepo = new PlatformRepository(array(), $platformOverrides);
$lockedRepo = null;
$phpVersion = $platformRepo->findPackage('php', '*')->getVersion();
if ($input->getOption('self')) {
@ -168,13 +170,27 @@ EOT
}
} elseif ($input->getOption('all') && $composer) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$installedRepo = new InstalledRepository(array($localRepo, $platformRepo));
$locker = $composer->getLocker();
if ($locker->isLocked()) {
$lockedRepo = $locker->getLockedRepository();
$installedRepo = new InstalledRepository(array($lockedRepo, $localRepo, $platformRepo));
} else {
$installedRepo = new InstalledRepository(array($localRepo, $platformRepo));
}
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
} elseif ($input->getOption('all')) {
$defaultRepos = RepositoryFactory::defaultRepos($io);
$io->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
$installedRepo = new InstalledRepository(array($platformRepo));
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
} elseif ($input->getOption('locked')) {
if (!$composer || !$composer->getLocker()->isLocked()) {
throw new \UnexpectedValueException('A valid composer.json and composer.lock files is required to run this command with --locked');
}
$locker = $composer->getLocker();
$lockedRepo = $locker->getLockedRepository();
$installedRepo = new InstalledRepository(array($lockedRepo));
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
} else {
$repos = $installedRepo = new InstalledRepository(array($this->getComposer()->getRepositoryManager()->getLocalRepository()));
$rootPkg = $this->getComposer()->getPackage();
@ -315,6 +331,8 @@ EOT
foreach ($repos as $repo) {
if ($repo === $platformRepo) {
$type = 'platform';
} elseif($lockedRepo !== null && $repo === $lockedRepo) {
$type = 'locked';
} elseif ($repo === $installedRepo || in_array($repo, $installedRepo->getRepositories(), true)) {
$type = 'installed';
} else {
@ -351,7 +369,7 @@ EOT
$exitCode = 0;
$viewData = array();
$viewMetaData = array();
foreach (array('platform' => true, 'available' => false, 'installed' => true) as $type => $showVersion) {
foreach (array('platform' => true, 'locked' => true, 'available' => false, 'installed' => true) as $type => $showVersion) {
if (isset($packages[$type])) {
ksort($packages[$type]);