[issue22047] argparse improperly prints mutually exclusive options when they are in a group

paul j3 report at bugs.python.org
Sat Jul 26 00:52:22 CEST 2014


paul j3 added the comment:

ArgumentGroups and MutuallyExclusiveGroups, as currently defined, won't give you that kind of usage.  I have appended a script that uses UsageGroups, which I am developing for http://bugs.python.org/issue11588, 
to solve this.

It defines 2 'mxg' groups (groups with the xor logic of mutually exclusive groups), and 1 'any' group.  They can be nested.

The resulting usage line is:

    usage: PROG [-h] [[--opt1 | --opt2 | --opt3] | [--opt4 --opt5 --opt6]]

Normally '|' is used for simple logical 'or'.  But in mutually exclusive groups it denotes 'xor'.  So what should join 'any' lists?  You chose ' ', I was using ','.  Defining a usage notation that is simple, intuitive, and also flexible, is not easy.

----------
Added file: http://bugs.python.org/file36095/issue22047.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22047>
_______________________________________


More information about the Python-bugs-list mailing list