yargs警告:提供的论点太多了。预计最多1但收到2

问题描述 投票:0回答:1

我的yargs配置存在问题:

const argv = require('yargs')
    .boolean('reset', {
        alias: 'rs'
    })
    .boolean('refreshConfig', {
        alias: 'rc'
    })
    .option('harvest', {
        alias: 'h'
    })
    .option('lang', {
        alias: 'l',
        default: 'fr'
    })
    .help().argv;

我执行这样的脚本:

node ./srcjobs/cli.js --refreshConfig --harvest = facebook

我收到此错误:

提供的论点太多了。预计最多1但收到2。

你知道为什么吗 ?谢谢您的帮助。

node.js yargs
1个回答
1
投票

.boolean从源代码中只收到1个参数

boolean<K extends string>(key: K | ReadonlyArray<K>): Argv<T & { [key in K]: boolean | undefined }>;

合适的方式

const argv = require('yargs')
  .boolean('reset')
  .alias('rs', 'reset')
  .boolean('refreshConfig')
  .alias('rc', 'refreshConfig')
  .option('harvest', {
    alias: 'h'
  })
  .option('lang', {
    alias: 'l',
    default: 'fr'
  })
  .help().argv;
© www.soinside.com 2019 - 2024. All rights reserved.