正在为 yargs 获取 "Invalid values:" 的消息
getting message for "Invalid values:" for yargs
我正在使用 yargs
开发一个 cli 工具。这是处理 cli 选项的简单 yargs
代码
let argv = require('yargs')
.usage('[=11=] <command> [option]')
.command(
'validate_zip',
'validate the directory structure for the zip to be uploaded',
{
'validate_zip': {
alias: 'vz'
}
}
)
.option('s', {
alias: 'stage',
describe: 'stage',
type: 'string',
choices: ['dev', 'qa', 'uat', 'prod'],
count: true
})
.demandCommand(1, 'You need at least one command before moving on!')
.help('h')
.alias('h', 'help')
.example('[=11=] validate_zip -s dev', 'testing yargs')
.showHelpOnFail(false, "Specify --help || -h for available options")
.argv;
这是cli命令
node testYargs.js vz -s dev
。我尝试通过 "dev"
,但遇到了同样的问题。
并显示以下消息
Invalid values:
Argument: s, Given: 1, Choices: "dev", "qa", "uat", "prod"
Specify --help || -h for available options
count 选项不应设置为 true。 count有特殊含义,表示应该统计一个flag出现的次数:
details about count. 可在原始 yargs
api 文档中找到。
所以-v -v -v
会设置v = 3
,这会破坏选择逻辑。
我正在使用 yargs
开发一个 cli 工具。这是处理 cli 选项的简单 yargs
代码
let argv = require('yargs')
.usage('[=11=] <command> [option]')
.command(
'validate_zip',
'validate the directory structure for the zip to be uploaded',
{
'validate_zip': {
alias: 'vz'
}
}
)
.option('s', {
alias: 'stage',
describe: 'stage',
type: 'string',
choices: ['dev', 'qa', 'uat', 'prod'],
count: true
})
.demandCommand(1, 'You need at least one command before moving on!')
.help('h')
.alias('h', 'help')
.example('[=11=] validate_zip -s dev', 'testing yargs')
.showHelpOnFail(false, "Specify --help || -h for available options")
.argv;
这是cli命令
node testYargs.js vz -s dev
。我尝试通过 "dev"
,但遇到了同样的问题。
并显示以下消息
Invalid values:
Argument: s, Given: 1, Choices: "dev", "qa", "uat", "prod"
Specify --help || -h for available options
count 选项不应设置为 true。 count有特殊含义,表示应该统计一个flag出现的次数:
details about count. 可在原始 yargs
api 文档中找到。
所以-v -v -v
会设置v = 3
,这会破坏选择逻辑。