我需要处理特定的选项,并将所有其他参数作为数组进一步传递。
例如:
我这样调用这个脚本:node script.js --one 1 --two 2 --three 3
const args = yargs(argv).demandOption("one").string("one").argv;
console.log(args.one);
const rest = ???
console.log(rest);应该这样写:
1
["--two", 2, "--three", 3]用纱线可以做到吗?类似于_的值,但是_只包含非选项值,所以我不能使用它。
发布于 2021-09-29 11:16:47
多亏了令人惊叹的yargs测试套件才找到了答案:https://github.com/yargs/yargs/blob/main/test/yargs.cjs#L1841
我只需要将yargs配置为也将未知选项传递给_:
const args = yargs(argv)
.parserConfiguration({'unknown-options-as-args': true})
.demandOption("one")
.string("one")
.argv;https://stackoverflow.com/questions/69374838
复制相似问题