我正在使用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创建子命令的最佳方法是什么?
发布于 2019-08-29 13:05:43
您可以创建以下结构:
- 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"我注意到的一件事是,如果您想要与其他命令共享一些标志或参数,则必须为此使用一个基类,或者在另一个文件上声明标志/开关/参数,并将它们导入所需的命令。
https://stackoverflow.com/questions/57701054
复制相似问题