Add error message for invalid argument value#244
Merged
jiasli merged 5 commits intomicrosoft:devfrom Apr 9, 2021
Merged
Conversation
- If user provided an invalid value for an argument with a list of choices, then the error message will not indicate this. Rather it will indicate that cli command group is invalid. This is a quick fix and I am not sure that it doesn't break Knack. From my tests, this fix is better than removing overridden _check_value method.
…rror messages - This seems to be a better fix for the previous commit.
jiasli
commented
Mar 26, 2021
| # Show suggestions | ||
| candidates = difflib.get_close_matches(value, action.choices, cutoff=0.7) | ||
| if candidates: | ||
| suggestion_msg = "\nThe most similar choices to '{value}':\n".format(value=value) |
Member
Author
There was a problem hiding this comment.
No need to play around with English grammar for third person singular form.
jiasli
commented
Mar 26, 2021
| name=argparse._get_action_name(action)) # pylint: disable=protected-access | ||
| logger.error(error_msg) | ||
| # Show all allowed values | ||
| suggestion_msg = "Allowed values: " + ', '.join(action.choices) |
Member
Author
There was a problem hiding this comment.
The number of allowed argument values is usually very limited. Show all of them.
fralik
approved these changes
Apr 5, 2021
fralik
approved these changes
Apr 5, 2021
| # Show suggestions | ||
| candidates = difflib.get_close_matches(value, action.choices, cutoff=0.7) | ||
| if candidates: | ||
| suggestion_msg = "\nThe most similar choices to '{value}':\n".format(value=value) |
| name=argparse._get_action_name(action)) # pylint: disable=protected-access | ||
| logger.error(error_msg) | ||
| # Show all allowed values | ||
| suggestion_msg = "Allowed values: " + ', '.join(action.choices) |
Merged
Merged
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #236
Migrated from #237
Symptom
Knack can only give error message for invalid command, but not invalid argument value.
History: #237 (comment)
Change
Add error message for invalid argument value.
Testing guide
ℹ As
Allowed values: rock, paper, scissorsappears in one line, it is not needed to add an empty line before it.