Skip to content

[Console] Synopsis in error message contains <command> as non-option argument #38906

Closed
@aadmathijssen

Description

@aadmathijssen

Symfony version(s) affected: 5.1.8

Description

When an exception occurs while validating or running a Symfony Console command, an error message is shown to the user.
The last line of the error message is a synopsis of how the command should be called. This synopsis is incorrect: it states that the first non-option argument should be <command>. But the command itself is already shown at the start of the synopsis.

How to reproduce

Install the Symfony skeleton and run the following command:

bin/console secrets:list --foo

An error is shown of which the last line is the following:

secrets:list [-r|--reveal] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

In this synopsis, <command> at the end of the line should not be there.

Similarly, the command

bin/console secrets:set --foo

also shows an error with the following last line:

secrets:set [-l|--local] [-r|--random [RANDOM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> <name> [<file>]

Also in this synopsis, <command> should not be there.

Possible Solution

Unknown.

Additional context

The synopsis is printed on line 774 of src/Symfony/Component/Console/Application.php. On this line the method \Symfony\Component\Console\Command\Command::getSynopsis is called, which in turn calls \Symfony\Component\Console\Input\InputDefinition::getSynopsis. In this method, all non-option arguments are enclosed in < and > and are added to the synopsis; this happens on line 375 of src/Symfony/Component/Console/Input/InputDefinition.php. So the first element of $this->getArguments() is an argument with name command.

This issue is possibly related to #38904.

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