Skip to content

[Console] HelpCommand strips arguments with same names as output styles #24225

Closed
@pbull

Description

@pbull
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.7.x, 3.3.x

When a console command defines one or more input arguments that have the same name(s) as defined OutputFormatterStyles, the HelpCommand output strips those arguments from the Usage section of the output and applies that style to the content that follows.

This is occurring because in Symfony\Component\Console\Input\InputDefinition::getSynopsis() (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Input/InputDefinition.php#L398) those argument names are wrapped in < and > and so the argument is treated as the opening tag of a style wrapper:

        foreach ($this->getArguments() as $argument) {
            $element = '<'.$argument->getName().'>';
[...]
        }

An example command that defines the argument names "info", "comment", and "foo" as follows:

    protected function configure() {
        $this->addArgument('info', InputArgument::REQUIRED, 'The first argument.');
        $this->addArgument('comment', InputArgument::OPTIONAL, 'The second argument.');
        $this->addArgument('foo', InputArgument::OPTIONAL, 'The third argument.');
    }

... would appear as follows when running help for that command. Note that the yellow foreground color of the default comment style is being applied to the following text in the output:

console1

... when the expected output would be more like:

console2

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