Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 5 commits into from
Closed

[Console] Fixed verbose option when passing verbosity level as option value #8835

wants to merge 5 commits into from

Conversation

deguif
Copy link
Contributor

@deguif deguif commented Aug 23, 2013

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

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 ;)

@jakzal
Copy link
Contributor

jakzal commented Aug 23, 2013

This PR breaks some tests.

@deguif
Copy link
Contributor Author

deguif commented Aug 23, 2013

Yes I'm currently working on fixing the tests.

@deguif
Copy link
Contributor Author

deguif commented Aug 23, 2013

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) {
Copy link
Member

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;
}

Copy link
Contributor

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);

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 with invalid argument exception

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point.

Copy link
Member

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.

@fabpot fabpot closed this in 47d080d Oct 1, 2013
fabpot added a commit that referenced this pull request Nov 22, 2013
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants