yargs:配置更改后更新帮助

时间:2018-11-30 12:59:43

标签: javascript npm command-line-interface yargs

我使用yargs解析两个文件中的命令行参数。 每个文件定义自己的参数集进行解析。 我在代码中同时使用了这两个文件。

common.js:

const { argv } = require('yargs')
  .option('a')
  .option('b')

const { a, b } = argv
module.exports = { a, b }

command.js:

const { a, b } = require('./commmon')

const { argv } = require('yargs')
  .option('c')
  .option('d')

const { c, d } = argv
console.log({ a, b, c, d }) // all options are parsed

bash:

$ node command.js --a 1 --b 2 --c 3 --d 4
{ a: 1, b: 2, c: 3, d: 4 }

$ node command.js --help
Options:
  --help     Show help                                                 
[boolean]
  --version  Show version number                                       
[boolean]
  -a
  -b   

当我运行node my-command.js --help时,仅获得有关通用配置的帮助。

在定义另一个配置时,是否可以说yargs更新其帮助?我希望它包含来自两个配置的参数描述。

0 个答案:

没有答案