From 077930807637f7bd3abcaa589bd311cdab510196 Mon Sep 17 00:00:00 2001 From: Kamil Bacia Date: Sat, 25 Apr 2020 19:29:32 +0200 Subject: [PATCH 1/2] close #8784, Added --locked option to composer show command. Displaying locked packages with --all option --- src/Composer/Command/ShowCommand.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 6cf1905f5..b3fac0f47 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -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]); From 6e7d7097e892ecd5c8eecadc2184f0b270e5b0df Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 28 Apr 2020 08:53:23 +0200 Subject: [PATCH 2/2] Add flag to docs --- doc/03-cli.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/03-cli.md b/doc/03-cli.md index 3a964c390..43ce287cc 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -357,6 +357,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.