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

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

问题描述

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

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天全站免登陆