close #8784, Added --locked option to composer show command. Displaying locked packages with --all option
parent
d6a9d78309
commit
0779308076
|
@ -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]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue