Skip to content

gh-94787: Add tip to put mutually-exclusive group into help group #94788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1930,7 +1930,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, you can still add a
mutually exclusive group to another group so they are organized within
the help messages as follows:

>>> parser = argparse.ArgumentParser(prog='PROG')
>>> group = parser.add_argument_group('Group title', 'Group desciption')
>>> 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 | --bar)

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

Group title:
Group desciption

--foo FOO foo help
--bar BAR bar help


Parser defaults
Expand Down