【发布时间】:2020-01-24 10:16:03
【问题描述】:
我一直在尝试,但就是无法消化 Yargs 的 docs。
我需要创建一组命令/子命令:
~$framework generate routed-module ModuleOne ModuleTwo ModuleThree --animation-style=bounce-up
//would call a handler with:
{ modules: string[], options: {animationStyle?: AnimationStyle}}
type AnimationStyle = 'bounce-up' | 'slide-left'
或
~$framework generate stateful-ui ModuleOne ModuleTwo ModuleThree
//would call a handler with:
{ modules: string[]}
或
~$framework init
//would just call a handler
我想要别名:
g 为 generate,
r 为 routed-module,
s 为stateful-ui。
自动补全会很好。
这是我尝试过的,不知道从哪里开始:
yargs
.scriptName('elm-framework')
.command({
command: 'generate [moduleType] [moduleNames]',
aliases: ['g'],
describe: 'Generates a resource',
handler: config.handleModuleGeneration,
builder: {
moduleType: {
demand: true,
choices: ['routed', 'stateful'] as const,
default: 'routed',
},
moduleNames: {
demand: true,
array: true,
},
},
})
谢谢!
(没有必要用打字稿做这个。我主要想了解如何使用库的api。)
【问题讨论】:
标签: javascript node.js typescript command-line-interface yargs