1
0
Fork 0

Merge pull request #9729 from Seldaek/restrict-why

Remove version argument from why and enforce it for why-not command
pull/9748/head
Nils Adermann 2021-02-25 23:35:59 +01:00 committed by GitHub
commit 41e329a458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 21 deletions

View File

@ -25,9 +25,7 @@ use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
/** /**
@ -38,25 +36,12 @@ use Symfony\Component\Console\Output\OutputInterface;
class BaseDependencyCommand extends BaseCommand class BaseDependencyCommand extends BaseCommand
{ {
const ARGUMENT_PACKAGE = 'package'; const ARGUMENT_PACKAGE = 'package';
const ARGUMENT_CONSTRAINT = 'constraint'; const ARGUMENT_CONSTRAINT = 'version';
const OPTION_RECURSIVE = 'recursive'; const OPTION_RECURSIVE = 'recursive';
const OPTION_TREE = 'tree'; const OPTION_TREE = 'tree';
protected $colors; protected $colors;
/**
* Set common options and arguments.
*/
protected function configure()
{
$this->setDefinition(array(
new InputArgument(self::ARGUMENT_PACKAGE, InputArgument::REQUIRED, 'Package to inspect'),
new InputArgument(self::ARGUMENT_CONSTRAINT, InputArgument::OPTIONAL, 'Optional version constraint', '*'),
new InputOption(self::OPTION_RECURSIVE, 'r', InputOption::VALUE_NONE, 'Recursively resolves up to the root package'),
new InputOption(self::OPTION_TREE, 't', InputOption::VALUE_NONE, 'Prints the results as a nested tree'),
));
}
/** /**
* Execute the command. * Execute the command.
* *
@ -83,7 +68,7 @@ class BaseDependencyCommand extends BaseCommand
list($needle, $textConstraint) = array_pad( list($needle, $textConstraint) = array_pad(
explode(':', $input->getArgument(self::ARGUMENT_PACKAGE)), explode(':', $input->getArgument(self::ARGUMENT_PACKAGE)),
2, 2,
$input->getArgument(self::ARGUMENT_CONSTRAINT) $input->hasArgument(self::ARGUMENT_CONSTRAINT) ? $input->getArgument(self::ARGUMENT_CONSTRAINT) : '*'
); );
// Find packages that are or provide the requested package first // Find packages that are or provide the requested package first

View File

@ -14,6 +14,8 @@ namespace Composer\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
/** /**
* @author Niels Keurentjes <niels.keurentjes@omines.com> * @author Niels Keurentjes <niels.keurentjes@omines.com>
@ -25,12 +27,15 @@ class DependsCommand extends BaseDependencyCommand
*/ */
protected function configure() protected function configure()
{ {
parent::configure();
$this $this
->setName('depends') ->setName('depends')
->setAliases(array('why')) ->setAliases(array('why'))
->setDescription('Shows which packages cause the given package to be installed.') ->setDescription('Shows which packages cause the given package to be installed.')
->setDefinition(array(
new InputArgument(self::ARGUMENT_PACKAGE, InputArgument::REQUIRED, 'Package to inspect'),
new InputOption(self::OPTION_RECURSIVE, 'r', InputOption::VALUE_NONE, 'Recursively resolves up to the root package'),
new InputOption(self::OPTION_TREE, 't', InputOption::VALUE_NONE, 'Prints the results as a nested tree'),
))
->setHelp( ->setHelp(
<<<EOT <<<EOT
Displays detailed information about where a package is referenced. Displays detailed information about where a package is referenced.

View File

@ -14,6 +14,8 @@ namespace Composer\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
/** /**
* @author Niels Keurentjes <niels.keurentjes@omines.com> * @author Niels Keurentjes <niels.keurentjes@omines.com>
@ -25,12 +27,16 @@ class ProhibitsCommand extends BaseDependencyCommand
*/ */
protected function configure() protected function configure()
{ {
parent::configure();
$this $this
->setName('prohibits') ->setName('prohibits')
->setAliases(array('why-not')) ->setAliases(array('why-not'))
->setDescription('Shows which packages prevent the given package from being installed.') ->setDescription('Shows which packages prevent the given package from being installed.')
->setDefinition(array(
new InputArgument(self::ARGUMENT_PACKAGE, InputArgument::REQUIRED, 'Package to inspect'),
new InputArgument(self::ARGUMENT_CONSTRAINT, InputArgument::REQUIRED, 'Version constraint, which version you expected to be installed'),
new InputOption(self::OPTION_RECURSIVE, 'r', InputOption::VALUE_NONE, 'Recursively resolves up to the root package'),
new InputOption(self::OPTION_TREE, 't', InputOption::VALUE_NONE, 'Prints the results as a nested tree'),
))
->setHelp( ->setHelp(
<<<EOT <<<EOT
Displays detailed information about why a package cannot be installed. Displays detailed information about why a package cannot be installed.