-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Fixed verbose option when passing verbosity level as option value #8835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This PR breaks some tests. |
Yes I'm currently working on fixing the tests. |
I just fix the tests. It was related to the changes from InputOption::VALUE_NONE to InputOption::VALUE_OPTIONAL |
$verbosity = 1; | ||
if ($input->hasParameterOption('--verbose')) { | ||
$verbosity = (int) $input->getParameterOption('--verbose'); | ||
if ($verbosity < 1 || $verbosity > 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have written:
if ($verbosity < 1) {
$verbosity = 1;
} elseif ($verbosity > 3) {
$verbosity = 3;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
$verbosity = min(max($verbosity, 1), 3);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thougth of this when writing the patch.
But because of the test beyond, I don't implement the patch this way.
$tester->run(array('command' => 'list', '--verbose' => 4));
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if unknown --verbose level is passed');
Will do this and fix the above test if you're ok with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, that is a bit vague indeed. Maybe it should just throw an invalidargumentexception instead? It doesn't make much sense to pass -5 or 10 as a value anyway. Allowing it only works confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 with invalid argument exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to min/max solution. If you try with someUnix command, you can add as many -v as you want, you will never get an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure that it still really works in a real world CLI app with -v/-vv/-vvv/--verbose=2/--verbose=3
. It was a pain to get it all working given the verbose stuff happens early on.. that's why the code looked wonky.
This PR was merged into the master branch. Discussion ---------- [Console] Revert BC-break for verbose option value | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9285 | License | MIT | Doc PR | ~ Closes #9285 ---- PR #8835 "fixed" the input value for verbosity option with `VALUE_OPTIONAL`. And syntax like ``` cli.php -v command cli.php --verbose command ``` Is broken now, because `ArgvInput` tries to use argument as verbose value (#9285). For now i added a test for this case and revert this changes. Commits ------- 432bbe1 [Console] Revert a28eb8 because of BC break 5e03e9a [Console] Add test for --verbose before argument
Currently passing a verbosity level to verbose option on console doesn't work unless using the shotcuts -v, -vv, -vvv.
This also fix accept_value in the xml generated by console help --xml for people using the xml output ;)