我一直在尝试,但是无法消化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。)
使用this crucial piece of documentation找出来:
yargs
.scriptName('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,
},
},
}).parse(process.argv)