neithere / argh

An argparse wrapper that doesn't make you say "argh" each time you deal with it.
http://argh.rtfd.org
GNU Lesser General Public License v3.0
369 stars 56 forks source link

duplicate choices in help with short/long arguments #133

Closed BrendanSimon closed 3 years ago

BrendanSimon commented 6 years ago

If I specify a short and long argument with a boolean default, I get something like: -u, --upper False

If I specifiy an argument with choices, I get both arguments listed, each with it's own set of (duplicated) choices. -f {yaml,json}, --format {yaml,json}

It would be better to have both arguments lists, but only one set of choices - something like: -f, --format {yaml,json}

Here is some sample code:

from argh import *

@dispatch_command
@arg('name')
@arg('-f', '--format', choices=['yaml','json'])
@arg('-u', '--upper')
def main(name, format='json', upper=False):
    msg='Hello {} (format={})'.format(name, format)
    if upper:
        msg = msg.upper()
    print(msg)

and sample output:

$ python3.6 foo.py -h
usage: foo.py [-h] [-f {yaml,json}] [-u] name

positional arguments:
  name                  -

optional arguments:
  -h, --help            show this help message and exit
  -f {yaml,json}, --format {yaml,json}
                        'json'
  -u, --upper           False
neithere commented 3 years ago

This is a good observation. However, I'm afraid the help is generated by Argparse. Not sure if we can affect this on Argh level in a sensible way. Please feel free to reopen if you have an idea how to do it.