如何解决yargs 表示通过 JSON 提供的嵌套参数“缺失”
使用 yargs 16.2.0,我定义了一些嵌套选项并通过配置文件提供它们,但 yargs 仍然声称它们丢失了:
yargs
yargs
.command('do-stuff','Does some neat stuff.',o => o
.option('test.something',{
type: 'string',demandOption: true,requiresArg: true,})
)
.strict()
.demandCommand()
.config('env')
.help()
.argv;
config.json
{
"test": {
"something": "blah"
}
}
通过...执行
> node index.js -- do-stuff --env config.json
index.js do-stu
Does some neat stuff.
Options:
--version Show version number [boolean]
--env Path to the environment config JSON from which to load
arguments.
--help Show help [boolean]
--test.something [string] [required]
Missing required argument: test.something
然后我编辑了 node_modules/yargs-parser/build/index.cjs
(original here) 并在解析配置 JSON 后添加了一行以注销 argv
:
setConfigObject(config); // line 630,existing
console.log(JSON.stringify(argv)); // added for debugging
结果输出:
{
"_": ["do-stuff"],"env": "config.json","test":
{
"something": "blah"
}
}
我在 node_modules/yargs/build/index.cjs
中进行了相同的更改,在第 1472 行之后(就在显示“缺少必需参数”消息之前,并且 JSON 输出仍然包含 test.something
参数。
那么,为什么 yargs 声称没有提供我的参数,即使 argv
显示它们提供了?
解决方法
这是 yargs 中的错误或不受支持的用例:https://github.com/yargs/yargs/issues/1782
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。