I am using the argparse Python module for command line subcommands in my program. My code basically looks like this:
import argparse parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(title="subcommands", metavar="<command>") subparser = subparsers.add_parser("this", help="do this") subparser = subparsers.add_parser("that", help="do that") parser.parse_args()
When running "python test.py --help", I would like to list the available subcommands. I am currently getting this output:
usage: test.py [-h] <command> ... optional arguments: -h, --help show this help message and exit subcommands: <command> this do this that do that
Is there any way to remove the <command> in the list of subcommands and save it in the usage line? I tried giving help = argparse.SUPPRESS as the add_subparsers argument, but that just hides all the subcommands in the help output.
python argparse
Jeppe ledet-pedersen
source share