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

Skip to content

[Console] Throw exception if value is passed to VALUE_NONE input optin, long syntax #8199

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

Conversation

tiagojsag
Copy link
Contributor

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

Input options with InputOption::VALUE_NONE accept values in both short and long syntaxes:

  • When using the long syntax, no exception is thrown;
  • When using short, a "The %s option does not exist" exception is thrown.

This PR only addresses the long syntax case. The short syntax case would require considerable refactoring of the parse code, which I believe should be discussed.

I included a test that illustrates the above mentioned problem for the long syntax scenario.

@Tobion
Copy link
Contributor

Tobion commented Jun 5, 2013

Why not go the other way round and do not throw an exception for both cases? It would also make it consistent but at the same time reduce the bc break and make it more user-friendly. It should just ignore the value.

@tiagojsag
Copy link
Contributor Author

I believe there's a design problem with the short syntax, tbh.

Consider the following example: app/console some:command -fo
This can be interpreted in several ways:
-f is the option short name, and 'o' the value passed to it
-f and -o are both options with no value

The current implementation always falls back to the second scenario, which is also reflected on the current tests. Changing the short syntax parser to accommodate this change would require significant changes, as the parser would need to look in all possible inputs, check if they admit or not arguments, and so on and so on.

And then you have the cases where -fo can actually be either things (-f is an input which admits a value and a -o option exists). And last but not least, this is my first PR to the main symfony project, so I don't mind doing the implementation, but I'd like some ideas from you guys on how this should be addressed.

edit: sorry, it's a bit late, and I just noticed i misread your post. If no exceptions are thrown, there's no point in declaring a VALUE_NONE. Also, I don't believe it would be user friendly. A user could (and can) do --foo=bar, the actual bar value is ignored, and the user is not notified.

fabpot added a commit that referenced this pull request Jun 13, 2013
This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #8199).

Discussion
----------

[Console] Throw exception if value is passed to VALUE_NONE input optin, long syntax

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8135
| License       | MIT

Input options with InputOption::VALUE_NONE accept values in both short and long syntaxes:
- When using the long syntax, no exception is thrown;
- When using short, a "The %s option does not exist" exception is thrown.

This PR only addresses the long syntax case. The short syntax case would require considerable refactoring of the parse code, which I believe should be discussed.

I included a test that illustrates the above mentioned problem for the long syntax scenario.

Commits
-------

32ea77f Throw exception if value is passed to VALUE_NONE input, long syntax
@fabpot fabpot closed this Jun 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants