【发布时间】:2015-11-08 02:53:30
【问题描述】:
我有一个包含多个命令的脚本,每个命令都使用 add_subparser 获取它自己的一组必需和/或可选参数。
=->test.py -h
usage: test.py [-h] <command> ...
positional arguments:
<command> Available Commands
cmd1 Command 1
cmd2 Command 2
cmd3 Command 3
cmd4 Command 4
optional arguments:
-h, --help show this help message and exit
=->test.py cmd1 -h
usage: test.py cmd1 [-h] --flag1 FLAG1
optional arguments:
-h, --help show this help message and exit
--flag1 FLAG1 Test flag
=->test.py cmd2 -h
usage: test.py cmd2 [-h] [--flag2 FLAG2]
optional arguments:
-h, --help show this help message and exit
--flag2 FLAG2 Test flag
我想以某种方式将这些命令分成组,以便用户看到如下内容:
=->test.py -h
usage: test.py [-h] <command> ...
First Group:
cmd1 Command 1
cmd2 Command 2
Second Group:
cmd3 Command 3
cmd4 Command 4
optional arguments:
-h, --help show this help message and exit
但是,add_argument_group 和 add_subparsers 似乎不能一起工作。
有什么方法可以做到这一点?
【问题讨论】: