Like many command line tools, mine accepts optional filenames. Argparse seems to support this via nargs='*', which is working for me as expected:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'files',
help='file(s) to parse instead of stdin',
nargs='*')
parser.parse_args()
However, the help output is bizarre:
$ ./help.py -h
usage: help.py [-h] [files [files ...]]
How can I avoid the nested optional and repeated parameter name? The repetition adds no information beyond [files ...], which is the traditional way optional parameter lists are indicated on Unix:
$ grep --help
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
$ ls --help
Usage:
exa [options] [files...]
$ vim --help
Usage:
nvim [options] [file ...] Edit file(s)
Any help is appreciated. I'm trying argparse because using it seems to be a Python best practice, but this help output is a dealbreaker for me.