I am wondering if I could parse arguments using Python and argparse
, like:
usage: PROG [-h] [--foo] (bar [baz] qux | file)
which allows following usages:
PROG aaa bbb ccc --foo # foo=True bar='aaa' baz='bbb' qux='ccc'
PROG aaa ccc --foo # foo=True bar='aaa' qux='ccc'
PROG /path/to/file --foo # foo=True file='/path/to/file'
We can have solutions (1) making foo
, bar
, baz
, qux
, and file
all optional, or (2) treating bar
, baz
, and qux
collectively as an array and creating a mutually exclusive group with file
and the array, however argument validation becomes complex in both ways.
4