SimpleParsing icon indicating copy to clipboard operation
SimpleParsing copied to clipboard

Make Help output of a program with subparsers prettier

Open lebrice opened this issue 3 years ago • 1 comments

It would be nice to somehow get a cleaner / more minimalist help output for programs that use the subparsers feature.

lebrice avatar Mar 07 '23 19:03 lebrice

E.g.:

import argparse

parser = argparse.ArgumentParser(prog="test")
group = parser.add_argument_group("global flags", description="bobobobo")
group.add_argument("--verbose", default=False, action="store_true")
group.add_argument("--debug", default=False, action="store_true")

subp = parser.add_subparsers()

parser_a = subp.add_parser("db", help="a help")
parser_a.add_argument("bar", type=int, help="bar help")

parser_b = subp.add_parser("acquire", help="b help")
parser_b.add_argument("--baz", choices="XYZ", help="baz help")

parser.print_help()
usage: test [-h] [--verbose] [--debug] {db,acquire} ...

positional arguments:
  {db,acquire}
    db          a help
    acquire     b help

options:
  -h, --help    show this help message and exit

global flags:
  bobobobo

  --verbose
  --debug

This is clean, even with an argument group. The ordering of options is a bit different as well..

lebrice avatar Mar 07 '23 19:03 lebrice