第3条。 科利语
由Art.Build(英语:Art. 配置符
安装
npm install art-cli
示例
简单示例 :
# CaffeineScript
&@ArtSuite/Cli.start
commands:
sing: ({song}) -> "♫ #{song} ♫!"
// JavaScript
require("@art-suite/cli").start({
commands: {
sing: ({ song }) => `♫ ${song} ♫!`
})
产出:
my-tool sing --song "I'm a lumberjack and I'm okay"
> ♫ I'm a lumberjack and I'm okay ♫!
分析
所有论据均使用以下规则进行解析. 这样可以使CLI的解析方式标准化。 它允许您通过结构化的数据 和定制javascript 在您的代码中从CLI.
命令、 参数和选项
myCli myCommand myArg --foo[] foo1 foo2 --bam boom myOtherArg
# command: "myCommand", options: {foo: ["foo1", "foo2"], bam: "boom"}, args: ["myArg", "myOtherArg"]
myCli myCommand myArg --foo=foo1 myOtherArg --bam
# command: "myCommand", options: {foo: "foo1", bam: true}, args: ["myArg", "myOtherArg"]
数值
# parse json from the command-line
myCli myCommand --myObj 'json:{"hi":123}'
# command: "myCommand", options: myObj: {hi: 123}
# parses javascript from the command-line for easy custom-function injection
myCli myCommand --myFunc "js:(v) => v + 1"
# command: "myCommand", options: myFunc: (v) => v + 1
# but wait, I want a string that starts out "js:..." - we've got you:
myCli myCommand --myFunc "string:js:foo"
# command: "myCommand", options: myFunc: "js:foo"
# all these work with args too
myCli myCommand "js:(v) => v + 1"
# command: "myCommand", args: [{myFunc: (v) => v + 1}]