summaryrefslogtreecommitdiffstats
path: root/Doc/library/argparse.rst
diff options
context:
space:
mode:
authorScott Main <smain@google.com>2022-09-18 08:05:43 (GMT)
committerGitHub <noreply@github.com>2022-09-18 08:05:43 (GMT)
commit810ae51787cf2222801cd6cf4ebb2d7fa175ae59 (patch)
tree99ebbae7047e828df648570ae98f9bd1a4573b50 /Doc/library/argparse.rst
parent670007abb45b76115377de1f2ff398be27685007 (diff)
downloadcpython-810ae51787cf2222801cd6cf4ebb2d7fa175ae59.zip
cpython-810ae51787cf2222801cd6cf4ebb2d7fa175ae59.tar.gz
cpython-810ae51787cf2222801cd6cf4ebb2d7fa175ae59.tar.bz2
gh-94787: [doc] Add to argparse doc an example of a mutually-exclusive group nested in an argument group (GH-94807)
Diffstat (limited to 'Doc/library/argparse.rst')
-rw-r--r--Doc/library/argparse.rst21
1 files changed, 20 insertions, 1 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index b2fa0b3..5d76ab0 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -2031,7 +2031,26 @@ Mutual exclusion
Note that currently mutually exclusive argument groups do not support the
*title* and *description* arguments of
- :meth:`~ArgumentParser.add_argument_group`.
+ :meth:`~ArgumentParser.add_argument_group`. However, a mutually exclusive
+ group can be added to an argument group that has a title and description.
+ For example::
+
+ >>> parser = argparse.ArgumentParser(prog='PROG')
+ >>> group = parser.add_argument_group('Group title', 'Group description')
+ >>> exclusive_group = group.add_mutually_exclusive_group(required=True)
+ >>> exclusive_group.add_argument('--foo', help='foo help')
+ >>> exclusive_group.add_argument('--bar', help='bar help')
+ >>> parser.print_help()
+ usage: PROG [-h] (--foo FOO | --bar BAR)
+
+ options:
+ -h, --help show this help message and exit
+
+ Group title:
+ Group description
+
+ --foo FOO foo help
+ --bar BAR bar help
.. versionchanged:: 3.11
Calling :meth:`add_argument_group` or :meth:`add_mutually_exclusive_group`