You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
{
protectedfunctionconfigure()
{
$this->setName('say')->addOption('foo', 'f')->addOption('bar', 'b');
}
protectedfunctionexecute(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.
The text was updated successfully, but these errors were encountered:
…erfit)
This PR was merged into the 2.7 branch.
Discussion
----------
[Console] Fix global console flag when used in chain
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks? | no
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass? | yes
| Fixed tickets | #23876
| License | MIT
| Doc PR |
Because SymfonyCon is great we can create pull request in it ! (this was preparer in the plane and I can push it just right now ;))
Finished in the #SymfonyConHackday2017
Commits
-------
1f8db73 [Console] Fix global console flag when used in chain
The parsing of global console flags is rather inconsistent with rest of the console application framework.
The
Application::configureIO()
useshasParameterOption
for testing flags, which in case ofArgvInput
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:
Now, if a run a command like
we get no input, as expected due to the "quiet" flag. However, should we run the command:
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.
The text was updated successfully, but these errors were encountered: