Skip to content

Commit

Permalink
Add hints when the arg of show is not found, fixes #10493
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Feb 4, 2022
1 parent ee36c5e commit d124c13
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Composer/Command/ShowCommand.php
Expand Up @@ -247,16 +247,21 @@ protected function execute(InputInterface $input, OutputInterface $output)

if (empty($package)) {
$options = $input->getOptions();
if (!isset($options['working-dir']) || !file_exists('composer.json')) {
if (PlatformRepository::isPlatformPackage($input->getArgument('package')) && !$input->getOption('platform')) {
throw new \InvalidArgumentException('Package ' . $packageFilter . ' not found, try using --platform (-p) to show platform packages.');
}
throw new \InvalidArgumentException('Package ' . $packageFilter . ' not found');
$hint = '';
if ($input->getOption('locked')) {
$hint .= ' in lock file';
}
if (isset($options['working-dir'])) {
$hint .= ' in ' . $options['working-dir'] . '/composer.json';
}
if (PlatformRepository::isPlatformPackage($input->getArgument('package')) && !$input->getOption('platform')) {
$hint .= ', try using --platform (-p) to show platform packages';
}
if (!$input->getOption('all')) {
$hint .= ', try using --all (-a) to show all available packages';
}

$io->writeError('Package ' . $packageFilter . ' not found in ' . $options['working-dir'] . '/composer.json');

return 1;
throw new \InvalidArgumentException('Package "' . $packageFilter . '" not found'.$hint.'.');
}
} else {
$versions = array($package->getPrettyVersion() => $package->getVersion());
Expand Down

0 comments on commit d124c13

Please sign in to comment.