Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
Yargs - can I get "rest" arguments?

I need to process specific option, and pass all other arguments further as an array.

For example:

I call the script like this: node script.js --one 1 --two 2 --three 3

const args = yargs(argv).demandOption("one").string("one").argv;
console.log(args.one);

const rest = ???
console.log(rest);

Should write:

1
["--two", 2, "--three", 3]

Is this doable with yargs? Something like the _ value, but _ only contains non-option values so I can't use that.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Found the answer thanks to amazing yargs' test suite: https://github.com/yargs/yargs/blob/main/test/yargs.cjs#L1841

I just need to configure the yargs to pass unknown options to _ too:

const args = yargs(argv)
    .parserConfiguration({'unknown-options-as-args': true})
    .demandOption("one")
    .string("one")
    .argv;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!