I hoped to nest argument groups to better document my options, especially given that it is not possible to add groups of mutually exclusive options. While nested argument groups give no errors at run-time, they do not seem display the relevant help text properly. For example, this:
import argparse
parser = argparse.ArgumentParser( formatter_class =
argparse.RawDescriptionHelpFormatter )
# add "level-1" argument group
ag1Parser = parser.add_argument_group( 'OneTwo', 'The old one-two options.' )
ag1Parser.add_argument( '-one', action='store_true', help = '''Set one.''' )
ag1Parser.add_argument( '-two', action='store_true', help = '''Set two.''' )
ag2Parser = ag1Parser.add_argument_group( 'Two options', 'Options only for use with -two.' )
ag2Parser.add_argument( '-three', action = 'store_true', help = '''Set three.''' )
parser.parse_args(['-h'])
produces the following output:
usage: [-h] [-one] [-two] [-three]
optional arguments:
-h, --help show this help message and exit
OneTwo:
The old one-two options.
-one Set one.
-two Set two.
You can see that -three is an option in the first line of output, and the level-1 argument group information is printed, but the nested level-2 group information does not appear. Does anyone know any way to get this to work with current argparse? If not, is it something worth adding to argparse
, even if it might have to come with depth restrictions?
Yes, I know I can just add a completely independent argument group, but I was hoping for something more like this (i.e. nested output):
usage: [-h] [-one] [-two] [-three]
optional arguments:
-h, --help show this help message and exit
OneTwo:
The old one-two options.
-one Set one.
-two Set two.
Two options:
Options only for use with -two.
-three Set three.
Thanks!