如何在组中显示argparse子命令? [英] how to show argparse subcommands in groups?

查看:42
本文介绍了如何在组中显示argparse子命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于具有许多子命令的程序,我想将它们按逻辑分组显示在--help输出中. Python argparse具有 add_argument_group 方法,但它没有似乎与次级解析器兼容.子解析器只能添加到顶级ArgumentParser,并且_SubParsersAction不允许参数组.有什么办法解决这个问题?

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?

推荐答案

除了实现自定义HelpFormatter之外,您不能以任何直接的方式真正做到这一点.

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

您可以在这部分中找到有关HelpFormatter风味的更多信息.文档.

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

这篇关于如何在组中显示argparse子命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆