Reputation: 1881
When using an argument (optional and positional both have this problem) with the keyword choices
, the generated help output shows those choices.
If that same argument also includes a metavar
keyword, the list of choices is omitted from the generated output.
What I had in mind, was to show the metavar
in the usage
line, but actually show the available choices when the 'autohelp' lists positional/optional argument details.
Any simple fixes/workarounds?
I have already started an argparse wrapper for custom help functionality. Perhaps this should be another feature on my TODO list.
Upvotes: 9
Views: 2450
Reputation: 231665
You can add the choices to the help text.
parser=argparse.ArgumentParser()
parser.add_argument('-f',metavar="TEST",choices=('a','b','c'),
help='choices, {%(choices)s}')
print parser.format_help()
produces:
usage: stack20328931.py [-h] [-f TEST]
optional arguments:
-h, --help show this help message and exit
-f TEST choices, {a, b, c}
Upvotes: 18