Why I can't I have an argparse
mutually exclusive group with a title
or description
, so that it appears as a separate category under the --help
message?
I have an options group with a name and a description:
import argparse
parser = argparse.ArgumentParser()
group = parser.add_argument_group(
'foo options', 'various (mutually exclusive) ways to do foo')
group.add_argument('--option_a', action='store_true', help='option a')
group.add_argument('--option_b', action='store_true', help='option b')
args = parser.parse_args()
Output of --help
:
usage: foo.py [-h] [--option_a] [--option_b]
optional arguments:
-h, --help show this help message and exit
foo options:
various (mutually exclusive) ways to do foo
--option_a option a
--option_b option b
But I want to make the group mutually exclusive:
import argparse
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group() # here
group.add_argument('--option_a', action='store_true', help='option a')
group.add_argument('--option_b', action='store_true', help='option b')
args = parser.parse_args()
Output of --help
:
usage: foo.py [-h] [--option_a | --option_b]
optional arguments:
-h, --help show this help message and exit
--option_a option a
--option_b option b
There is no distinction in the help message that these options are part of a group, and I can't specify a title/description (add_mutually_exclusive_group takes no additional positional arguments). Does anyone have a workaround?