0

I have an issue with my yargs configuration:

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

I executed the script as below:

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

and I received this error:

Too many arguments provided. Expected max 1 but received 2.

Do you know why ? Thank you for your help.

anlgrses
  • 371
  • 4
  • 12
Vivien Adnot
  • 1,157
  • 3
  • 14
  • 30

1 Answers1

1

.boolean receive only 1 argument, from source code

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

Proper way

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;
Medet Tleukabiluly
  • 11,662
  • 3
  • 34
  • 69