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

查看:27
本文介绍了如何在组中显示 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.

您可以在 文档的这一部分.

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

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

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