multiple usage strings

22 views
Skip to first unread message

Steve

unread,
Dec 2, 2011, 4:41:08 PM12/2/11
to argparse-users
Hello,

Is there a recommended way to leverage argparse to define multiple
usage strings (for example, to illustrated mutually exclusive use
cases). E.g.:

myscript.py [-h] [--version]
myscript.py [-f FOO] infile [infile ...]

The best I've come up with so far is to create sets of specifications
for add_parser. First, create a parser for each set just to get the
usage string, then create a final parser with all arguments and
specify the combined usage strings as the final usage string.

Thanks

Steven Bethard

unread,
Dec 15, 2011, 8:34:29 AM12/15/11
to argpars...@googlegroups.com

Yeah, that sounds like the best you can do currently. The only way you
can currently get two separate usage strings is with subparsers, where
you'd have something like:

myscript.py command1 [-h] [--version]
myscript.py command2 [-f FOO] infile [infile ...]

You might be able to trick subparsers into doing what you want, but it
probably wouldn't be pretty. ;-)

Steve
--
Where did you get that preposterous hypothesis?
Did Steve tell you that?
        --- The Hiphopopotamus

Reply all
Reply to author
Forward
0 new messages