Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Command: Adding argument called 'command' makes other args/options unreadable #54729

Copy link
Copy link
Open
@cavias

Description

@cavias
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.