There was a question that asked where they come from, and the accepted answer was a bunch of links to tutorials and source code. Explanation for argparse python modul behaviour: Where do the capital placeholders come from?
None of it was helpful to me, I want to either get rid of them, or know their purpose.
For example, a line like this:
parser.add_argument('-c', '--chunksize', type=int, help='chunk size in bits')
produces garbage like this:
optional arguments:
-h, --help show this help message and exit
-c CHUNKSIZE, --chunksize CHUNKSIZE
chunk size in bits
and if I try with an empty metavar string:
parser.add_argument('-c', '--chunksize', metavar='', type=int, help='chunk size in bits')
I get a space after the comma:
optional arguments:
-h, --help show this help message and exit
-c , --chunksize chunk size in bits
seems to work
You can make your formatter class to format the arguments whichever way you want. It's not entirely straight forward, but here's one that produces the following output (assuming @mgilson is correct in the assumption that you wanted to only display the metavar once for the set of command names... Otherwise just specify an actual
metavar='value'
and it will display precisely that text.):And the code for the class and reproducing the two outputs:
edit: To not show a metavar at all, you can pass an empty string to metavar:
The difference between doing that with the original class and the new class is the lack extra space character after the short command syntax.