File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -2031,7 +2031,26 @@ Mutual exclusion
2031
2031
2032
2032
Note that currently mutually exclusive argument groups do not support the
2033
2033
*title * and *description * arguments of
2034
- :meth: `~ArgumentParser.add_argument_group `.
2034
+ :meth: `~ArgumentParser.add_argument_group `. However, a mutually exclusive
2035
+ group can be added to an argument group that has a title and description.
2036
+ For example::
2037
+
2038
+ >>> parser = argparse.ArgumentParser(prog='PROG')
2039
+ >>> group = parser.add_argument_group('Group title', 'Group description')
2040
+ >>> exclusive_group = group.add_mutually_exclusive_group(required=True)
2041
+ >>> exclusive_group.add_argument('--foo', help='foo help')
2042
+ >>> exclusive_group.add_argument('--bar', help='bar help')
2043
+ >>> parser.print_help()
2044
+ usage: PROG [-h] (--foo FOO | --bar BAR)
2045
+
2046
+ options:
2047
+ -h, --help show this help message and exit
2048
+
2049
+ Group title:
2050
+ Group description
2051
+
2052
+ --foo FOO foo help
2053
+ --bar BAR bar help
2035
2054
2036
2055
.. versionchanged :: 3.11
2037
2056
Calling :meth: `add_argument_group ` or :meth: `add_mutually_exclusive_group `
You can’t perform that action at this time.
0 commit comments