繁体   English   中英

yargs 说通过 JSON 提供的嵌套 arguments “缺失”

[英]yargs says nested arguments provided via JSON are “missing”

使用 yargs 16.2.0,我定义了一些嵌套选项并通过配置文件提供它们,但 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

生成的 output:

{
    "_": ["do-stuff"],
    "env": "config.json",
    "test":
    {
        "something": "blah"
    }
}

我在node_modules/yargs/build/index.cjs中进行了相同的更改,在第 1472 行之后(就在显示“缺少所需参数”消息之前,并且 JSON output 仍然包含test.something参数。


那么,为什么 yargs 声称我的论点没有提供,即使argv也表明它们是?

这是 yargs 中的错误或不受支持的用例: https://github.com/yargs/yargs/issues/1782

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM