[英]How can I create Git-style subcommands with oclif?
I'm writing a CLI using Heroku's CLI framework oclif. 我正在使用Heroku的CLI框架oclif编写CLI。 It works great, but I would like to have Git-like subcommands, something like that:
它很好用,但是我想拥有类似Git的子命令,就像这样:
$ mycli mycommand subcommand
$ mycli mycommand subcommand --flags="are awesome"
$ mycli mycommand another-subcommand --name="John Doe"
I've gone through the docs but I couldn't find any information related to command structure, layout, hierarchy, etc. I could write mycommand
as a normal command and have a switch on argv's first argument, but my subcommands accept different flags, so I lose oclif's ability to report some help when someone runs mycli help mycommand
. 我浏览了文档,但是找不到与命令结构,布局,层次结构等有关的任何信息。我可以将
mycommand
编写为普通命令,并打开argv的第一个参数,但是我的子命令接受不同的标志,所以当有人运行mycli help mycommand
时,我失去了oclif报告某些帮助的能力。
So, my question is: what is the best way to create subcommands using oclif? 因此,我的问题是: 使用oclif创建子命令的最佳方法是什么?
You can create the following structure: 您可以创建以下结构:
- src
--- commands // all your commands will be on this folder
----- subcommand1 // if you have more commands from after subcomand1 include them in this folder like the one bellow.
------ command.js // a simple command
----- subcommand2.js
This would produce commands like: 这将产生如下命令:
cli subcommand1 command --some-flag --some-argument="xpto"
cli subcommand2 --some-other-flag --some-other-argument="WAT"
One thing that I've noticed is that if you want to share some flags or arguments with other commands you either will have to use a base class for that or declare the flags/switches/arguments on another file and import them on the desired command 我注意到的一件事是,如果您想与其他命令共享一些标志或参数,则要么必须为此使用基类,要么在另一个文件上声明标志/开关/参数,然后将它们导入所需的命令中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.