Nullset
unread,Oct 13, 2010, 5:16:55 AM10/13/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to argparse-users
When defining multiple mutual exclusion groups, each successive group
is nested in the previous group's square brackets when printed in the
usage blurb. It does not appear to have any effect on the logic - just
the display.
Example (redacted):
parser = argparse.ArgumentParser(description='...', epilog='...')
prompt_group = parser.add_mutually_exclusive_group()
prompt_group.add_argument('-f','--force', action='store_true')
prompt_group.add_argument('-i', action='store_true', default=True)
prompt_group.add_argument('-I', action='store_true')
prompt_group.add_argument('--interactive', action='store',
metavar='WHEN', choices=['never','once','always'])
dereference_group = parser.add_mutually_exclusive_group()
dereference_group.add_argument('-H', action='store_true')
dereference_group.add_argument('-L','--dereference',
action='store_true')
dereference_group.add_argument('-P','--no-dereference',
action='store_true', default=True)
preserve_root_group = parser.add_mutually_exclusive_group()
preserve_root_group.add_argument('--no-preserve-root',
action='store_true')
preserve_root_group.add_argument('--preserve-root',
action='store_true', default=True)
parser.add_argument('SOURCE', action='append', nargs='+')
When run:
$ prog --help
Produces:
usage: prog [-h]
[-f | -i | -I | --interactive WHEN [-H | -L | -P [--no-
preserve-root | --preserve-root]
SOURCE [SOURCE ...]
...
positional arguments:
SOURCE
optional arguments:
-h, --help show this help message and exit
-f, --force ...
-i ...
-I ...
--interactive WHEN ...
-H ...
-L, --dereference ...
-P, --no-dereference ...
--no-preserve-root ...
--preserve-root ...
...