Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show argparse subcommands in groups?

For a program with many subcommands, I'd like to show them logically grouped in the --help output. Python argparse has a add_argument_group method, but it doesn't seem compatible with subparsers. subparsers can only be added to the top level ArgumentParser, and _SubParsersAction doesn't allow argument groups. Is there some way around this?

like image 504
poolie Avatar asked Oct 06 '22 05:10

poolie


1 Answers

You can't really do it in any straightforward way, other than implementing a custom HelpFormatter.

You can find some more information on HelpFormatter flavors in this part of the documentation.

like image 107
favoretti Avatar answered Oct 10 '22 01:10

favoretti