[issue17218] support title and description in argparse add_mutually_exclusive_group

paul j3 report at bugs.python.org
Fri Apr 18 00:27:44 CEST 2014


paul j3 added the comment:

The idea of nesting a mutually_exclusive_group in a titled argument_group is already present in `test_argparse.py`.

    class TestMutuallyExclusiveInGroup(MEMixin, TestCase):

    def get_parser(self, required=None):
        parser = ErrorRaisingArgumentParser(prog='PROG')
        titled_group = parser.add_argument_group(
            title='Titled group', description='Group description')
        mutex_group = \
            titled_group.add_mutually_exclusive_group(required=required)
        mutex_group.add_argument('--bar', help='bar help')
        mutex_group.add_argument('--baz', help='baz help')
        return parser

    failures = ['--bar X --baz Y', '--baz X --bar Y']
    successes = [
        ('--bar X', NS(bar='X', baz=None)),
        ('--baz Y', NS(bar=None, baz='Y')),
    ]
    successes_when_not_required = [
        ('', NS(bar=None, baz=None)),
    ]

    usage_when_not_required = '''\
        usage: PROG [-h] [--bar BAR | --baz BAZ]
        '''
    usage_when_required = '''\
        usage: PROG [-h] (--bar BAR | --baz BAZ)
        '''
    help = '''\

        optional arguments:
          -h, --help  show this help message and exit

        Titled group:
          Group description

          --bar BAR   bar help
          --baz BAZ   baz help
        '''
 
So now the question is - do we to modify `add_mutually_exclusive_group` to streamline this task?  An alternative is to add a note to the documentation, eg.

    Note that currently mutually exclusive argument groups do not     
    support the title and description arguments of add_argument_group().
    However a such a group can be added to a titled argument group.
    (and then add an example)

----------

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


More information about the Python-bugs-list mailing list