-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fixed parser bug assuming value parsed is part of command #6636
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
Changes from 1 commit
ce25789
cd6bf4b
bd3b25b
f61d3ca
7a1427b
f43b034
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,18 +150,25 @@ def _check_value(self, action, value): | |
| # Override to customize the error message when a argument is not among the available choices | ||
| # converted value must be one of the choices (if specified) | ||
| if action.choices is not None and value not in action.choices: | ||
| error_msg = "{prog}: '{value}' is not an {prog} command. See '{prog} --help'.".format(prog=self.prog, | ||
| value=value) | ||
| if not self.command_source: | ||
| # parser has no `command_source`, value is part of command itself | ||
| error_msg = "{prog}: '{value}' is not in the '{prog}' command-group. See '{prog} --help'.".format( | ||
| prog=self.prog, value=value) | ||
| else: | ||
| # `command_source` indicates command values have been parsed, value is an argument | ||
| parameter = action.option_strings[0] if action.option_strings else action.dest | ||
| error_msg = "{prog}: '{value}' is not a valid value for '{param}'. See '{prog} --help'.".format( | ||
| prog=self.prog, value=value, param=parameter) | ||
| telemetry.set_user_fault(error_msg) | ||
| logger.error(error_msg) | ||
| candidates = difflib.get_close_matches(value, action.choices, cutoff=0.8) | ||
| candidates = difflib.get_close_matches(value, action.choices, cutoff=0.7) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the rationale behind this change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt it a little too strict; This isn't the main purpose of this PR, however, and I can change this back if you guys prefer
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with it--just wanted to know the reason. |
||
| if candidates: | ||
| print_args = { | ||
| 's': 's' if len(candidates) > 1 else '', | ||
| 'verb': 'are' if len(candidates) > 1 else 'is', | ||
| 'value': value | ||
| } | ||
| suggestion_msg = "\nThe most similar command{s} to '{value}' {verb}:\n".format(**print_args) | ||
| suggestion_msg = "\nThe most similar choice{s} to '{value}' {verb}:\n".format(**print_args) | ||
| suggestion_msg += '\n'.join(['\t' + candidate for candidate in candidates]) | ||
| print(suggestion_msg, file=sys.stderr) | ||
|
|
||
|
|
||
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.
No need to hyphenate command group.