Consider the following code:
import argparse
p = argparse.ArgumentParser(usage="Here we go gathering nuts in May", prog="runfiles.py")
p.add_argument('-a', '--arg0')
s = p.add_subparsers(help="subcommand help", title="subcommands", description="valid subcommands")
sp = s.add_parser(name="subparser1")
sp.add_argument("--arg5", help="help me", metavar="BABYLON5")
sp.add_argument("--arg6", help="help", metavar="BEATLES")
p.parse_args(["--help"])
The output will be:
usage: Here we go gathering nuts in May
optional arguments:
-h, --help show this help message and exit
-a ARG0, --arg0 ARG0
subcommands:
valid subcommands
{subparser1} subcommand help
And if I specify the subcommand, the help message is:
usage: Here we go gathering nuts in May subparser1 [-h] [--arg5 BABYLON5] [--arg6 BEATLES]
optional arguments:
-h, --help show this help message and exit
--arg5 BABYLON5 help me
--arg6 BEATLES help
There seems no way to generate help for the --arg5
and --arg6
options, which are specific to the subcommand {subparser1}
, at the global level, or for the global argument --arg0
to be described at the subcommand level.
Anyone know how to do this?