[英]How can I create Git-style subcommands with oclif?
我正在使用Heroku的CLI框架oclif编写CLI。 它很好用,但是我想拥有类似Git的子命令,就像这样:
$ mycli mycommand subcommand
$ mycli mycommand subcommand --flags="are awesome"
$ mycli mycommand another-subcommand --name="John Doe"
我浏览了文档,但是找不到与命令结构,布局,层次结构等有关的任何信息。我可以将mycommand
编写为普通命令,并打开argv的第一个参数,但是我的子命令接受不同的标志,所以当有人运行mycli help mycommand
时,我失去了oclif报告某些帮助的能力。
因此,我的问题是: 使用oclif创建子命令的最佳方法是什么?
您可以创建以下结构:
- 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
这将产生如下命令:
cli subcommand1 command --some-flag --some-argument="xpto"
cli subcommand2 --some-other-flag --some-other-argument="WAT"
我注意到的一件事是,如果您想与其他命令共享一些标志或参数,则要么必须为此使用基类,要么在另一个文件上声明标志/开关/参数,然后将它们导入所需的命令中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.