Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Help output of a program with subparsers prettier #230

Open
lebrice opened this issue Mar 7, 2023 · 1 comment
Open

Make Help output of a program with subparsers prettier #230

lebrice opened this issue Mar 7, 2023 · 1 comment

Comments

@lebrice
Copy link
Owner

lebrice commented Mar 7, 2023

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

@lebrice
Copy link
Owner Author

lebrice commented Mar 7, 2023

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..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant