我正在使用Python开发一个包含约40个子命令的程序。解析器是使用argparse完成的。随着子命令数量的增加,查找所需命令变得越来越复杂。当前显示如下。
$ pgrm -h
Usage: pgrm [-h] [-v] ...
Blabla bla.
Main command arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
Available sub-commands:
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
Usage example:
'pgrm sub-command -h' for more information.
我希望更改显示方式,以显示类别(例如更新/插入/选择)和相关子命令。
$ pgrm -h
Usage: pgrm [-h] [-v] ...
Blabla bla.
Main command arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
Available sub-commands:
Updating
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
Selecting
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
Inserting
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
sub_cmd Some description about the command…
有没有解决方案可以在 argparser 中实现这样的 CLI?谢谢。