diff -r 2cd0aa44d53c Doc/library/argparse.rst --- a/Doc/library/argparse.rst Wed Jan 21 00:47:54 2015 -0500 +++ b/Doc/library/argparse.rst Thu Jan 22 02:33:58 2015 +0000 @@ -1765,6 +1765,45 @@ :meth:`~ArgumentParser.add_argument_group`. +Mutual dependence +^^^^^^^^^^^^^^^^^ + +.. method:: ArgumentParser.add_mutually_dependence_group(required=False) + + Create a mutually dependence group. :mod:`argparse` will make sure that all + the arguments in the mutually dependence group was present on the + command line:: + + >>> parser = argparse.ArgumentParser(prog='PROG') + >>> group = parser.add_mutually_dependence_group() + >>> group.add_argument('--foo') + >>> group.add_argument('--bar') + >>> parser.parse_args(['--foo', 'f', '--bar', 'b']) + Namespace(bar='b', foo='f') + >>> parser.parse_args(['--foo', 'f']) + PROG: error: --foo dependence on --bar + >>> parser.parse_args(['--bar', 'b']) + PROG: error: --bar dependence on --foo + + The :meth:`add_mutually_dependence_group` method also accepts a *required* + argument, to indicate that all of the mutually dependence arguments is + required:: + + >>> parser = argparse.ArgumentParser(prog='PROG') + >>> group = parser.add_mutually_dependence_group(required=True) + >>> group.add_argument('--foo') + >>> group.add_argument('--bar') + >>> parser.parse_args([]) + usage: PROG [-h] (--foo | --bar) + PROG: error: the arguments --foo --bar is required + + Note that currently mutually dependence argument groups do not support the + *title* and *description* arguments of + :meth:`~ArgumentParser.add_argument_group`. And The ``action`` keyword argument + of :meth:`~ArgumentParser.add_argument` not allowed with ``'store_true'`` and + ``'store_false'`` + + Parser defaults ^^^^^^^^^^^^^^^