多级 argparse 子解析器 [英] Multiple level argparse subparsers

查看:27
本文介绍了多级 argparse 子解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在子解析器中有多个级别的子解析器,但是当我运行带有帮助标志的程序时,我只能看到顶级选项的帮助消息和选项.如何查看所有子选项或更深层次的特定子选项的帮助?

I have multiple levels of subparsers within subparsers, but when I run the program with help flag, I see help messages and choices only for top level options. How can I see help for all suboptions, or for specific suboption in deeper level?

推荐答案

要获得子解析器的帮助,请使用类似 python prog.py cmd1 -h 的命令.要获得子子解析器的帮助,python prog.py cmd1 cmd12 -h 应该可以工作.

To get the help for a subparser, use a command like python prog.py cmd1 -h. To get the help for a sub-subparser, python prog.py cmd1 cmd12 -h should work.

默认帮助机制无法通过一个命令显示主解析器和所有子解析器(和子子解析器)的帮助.只是太复杂了.

There isn't a means, with the default help mechanism, to show the help for the main parser and all the subparsers (and sub-subparsers) with one command. It just gets too complicated.

我建议自定义用法和描述.这包括子解析器的标题和描述等.

I'd suggest custom usage and description. That includes titles and descriptions for the subparsers, etc.

这篇关于多级 argparse 子解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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