When using argparse in python 3.6, I've noticed that if I supply the 'choices' attr when adding one of the arguments, then in the help menu's section for that argument, the list of choices themselves show up rather than the name of the argument.
Using this stackoverflow answer Python argparse: Lots of choices results in ugly help output, I found to use the 'metavar' and 'numargs' attrs to try and clean up the help menu. While this gets rid of the ugly choices being displayed as a hash, the name of the option still does not display at all in help.
Example...
This:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("works", type=int,
help="Shows up properly")
parser.add_argument("nope", type=int, choices=[1,2,3],
help="foobared")
parser.add_argument("nope2", type=int, choices=[1,2,3], nargs='?', metavar='',
help="still foobared")
parser.add_argument("why", type=int,
help="help me")
parser.parse_args()
Results in this help output:
$ python myparser.py --help
usage: myparser.py [-h] works {1,2,3} why
positional arguments:
works Shows up properly
{1,2,3} foobared
still foobared
why help me
optional arguments:
-h, --help show this help message and exit
This has to be simple... Can someone please advise me where I'm going wrong?