Closed
Description
argparse guesses
Print the possible (nearest) value of the argument. If options are specified with the choices
argument.
Pitch
argparse are end user oriented.
Such a message will make the program interface more user-friendly.
def main():
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('family', type=str.casefold, help='Font family', choices=get_all_family_names(FAMILY_FILES))
args = arg_parser.parse_args(['S200Flora'])
Now outputs this:
error: argument family: invalid choice: 's200flora' (choose from 'a431', ..., 's200flor', ... 'wingdings 3')
I suggest making the output look like this:
error: argument family: invalid choice: 's200flora', maybe you meant 's200flor'? (choose from 'a431', ..., 's200flor', ... 'wingdings 3')
It doesn't have to look exactly like this. I'm not talking about the implementation, perhaps the assumptions should always be (if there are matches) in the presence of the choices argument, perhaps only in some certain conditions.
These questions are decided by those who will implement it, as they see fit.
Previous discussion
Add “maybe you meant” in argparse choices
argument on discuss.python.org
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
Doc issues