Open
Description
Symfony version(s) affected
7.0.6
Description
Adding an argument called "command" to a custom Symfony command seems to conflict with the internal "command" value, making other parameters inaccessible.
There should probably be some filter/fix for this.
How to reproduce
Step 1: Create the following Command (Just add your own namespacing and such):
#[AsCommand(
name: 'some:command',
description: 'Some command doing something.',
)]
class SomeCommand extends Command
{
protected function configure(): void
{
$this
// The issue seems to be adding an argument called "command"
->addArgument('command', InputArgument::REQUIRED)
->addArgument('action', InputArgument::REQUIRED)
->addOption('cavia', 'c', InputOption::VALUE_REQUIRED, 'Cavialiefde');
}
public function run(InputInterface $input, OutputInterface $output): int
{
// This is fine and returns "some:command"
$command = $input->getArgument('command');
// This fails with InvalidArgumentException "The "action" argument does not exist."
// Even though it is clearly registered.
$action = $input->getArgument('action');
// This also fails with InvalidArgumentException "The "cavia" option does not exist."
// Even though it is clearly registered.
$cavia = $input->getOption('cavia');
return Command::SUCCESS;
}
}
Step 2: Run php bin/console some:command whatever thing --cavia=cavia
Possible Solution
In my opinion I should be able to get the 'command' argument as well as the other registered arguments and options.
Or the 'command' should be illegal as custom argument name and produce an Exception for that.
Or the argument 'command' should be handled separately from the internal commandname.
Additional Context
Note: I don't have a usecase for this. I just came across this while testing.