Skip to content

Global console flags don't work when providing multiple options #23876

Closed
@Riimu

Description

@Riimu
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version v3.3.6

The parsing of global console flags is rather inconsistent with rest of the console application framework.

The Application::configureIO() uses hasParameterOption for testing flags, which in case of ArgvInput does not seem to account for multiple flags provided in a single argument. i.e. it only tests for say, -q and -n separately, but not for -qn

To illustrate the issue, let's say, for example, that we have a command like:

class FooBarCommand extends Command
{
    protected function configure()
    {
        $this->setName('say')->addOption('foo', 'f')->addOption('bar', 'b');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($input->getOption('foo')) {
            $output->write('foo');
        }
        if ($input->getOption('bar')) {
            $output->write('bar');
        }
    }
}

Now, if a run a command like

> php console say -q -f -b

we get no input, as expected due to the "quiet" flag. However, should we run the command:

> php console say -qfb
foobar

We suddenly get the output "foobar". This is even a bit more confusing, since there is no error or anything to indicate that we did something wrong. The "q" flag is defined as a shortcut for "quiet", so it doesn't cause validation errors, but since the "q" flag is only noticed, if it's provided exactly in the format of "-q", it's also ignored.

Even if this is intended, it's even more confusing, since the "help" command makes no mention of the special status of the "-n" and "-q" flags which must be provided separately.

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