From d124c13a4246d8db7cb8513cd084ac2ad16ca1e9 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 4 Feb 2022 16:17:02 +0100 Subject: [PATCH] Add hints when the arg of show is not found, fixes #10493 --- src/Composer/Command/ShowCommand.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index f1f52f90b7a2..6df57e08c75f 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -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());