【问题标题】:customizing positional command arguments with yargs使用 yargs 自定义位置命令参数
【发布时间】:2017-02-22 14:34:23
【问题描述】:

我正在尝试将 yargs 用于命令行应用程序,但我的位置参数遇到了问题。

我有:

require('yargs')
    .command(
        'my-command <value>',
        'This command does someting'
        (y) => {
            return y
                .option('my-option', {
                    describe: "Some option",
                    demandOption: true
                })
         }
         (args) => {
             //execute my command here
         }
    )
    .help()
    .completion()
    .argv

这让我可以打电话:

my-program my-command my-value --my-option=hello!

而 args.value 现在包含“my-value”。

到目前为止一切顺利。然而问题是“值”参数没有出现在帮助文本中。我还想进一步限制 value 参数,基本上添加一个选择数组。但我只能找到如何使用产生 -- 标志的 .option() 函数来做到这一点。比如 --my-option。

是否可以像自定义 -- 选项一样自定义位置参数?

【问题讨论】:

    标签: node.js command-line-arguments yargs


    【解决方案1】:

    似乎不支持此功能。 https://github.com/yargs/yargs/issues/541

    问题已关闭,因此很可能不会很快实施。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-11
      • 2011-06-14
      • 2011-01-07
      • 1970-01-01
      • 2022-10-21
      • 1970-01-01
      相关资源
      最近更新 更多