To avoid spamming my users with a huge ugly interspersed list of dozens of subcommands, I simply set the metavar attribute of the metavar object. My code looks like this:
import argparse parser = argparse.ArgumentParser(description='Qaru example') subs = parser.add_subparsers() subs.metavar = 'subcommand' sub = subs.add_parser('one', help='does something once') sub = subs.add_parser('two', help='does something twice') parser.parse_args()
And the output of running this script with a single -h argument:
usage: tmp.py [-h] subcommand ... Qaru example positional arguments: subcommand one does something once two does something twice optional arguments: -h, --help show this help message and exit
The result is not exactly what you will illustrate as your best-desired case, but I think it might be the closest you can get without subclassing argparse.ArgumentParser and overriding what you need to configure, which would be dirty work.
source share