how to show argparse subcommands in groups?

感情迁移 提交于 2019-12-10 15:44:49

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13020898/how-to-show-argparse-subcommands-in-groups

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!