Questions tagged [yargs]

Yargs is a node.js package that helps you build interactive command line tools, by parsing arguments and generating an elegant user interface. Use this tag for questions relating to the Yargs node.js library.

143 questions
3
votes
3 answers

yargs: Require at least one argument without a corresponding flag

I am building a Node CLI app that needs to be passed a single file as an argument. For example: myapp.js /Users/jdoe/my_file.txt I know I can reference /Users/jdoe/my_file.txt through the _ object in yargs but how do I require that it be provided? …
Brady Holt
  • 2,844
  • 1
  • 28
  • 34
3
votes
1 answer

yargs takes only the first word of commandline input string

I am working on a node.js commandline weather app from a tutorial, i realized that when I enter a string as input, only the first word is taken, the string is split into an array of words and only the first word is returned app.js const yargs =…
David Essien
  • 1,463
  • 4
  • 22
  • 36
3
votes
2 answers

Yargs - How to provide custom error msg for omitted positional argument

I can't find a way to properly configure positional arguments. I have this code: #!/usr/bin/env node const create = (argv) => { console.log('create component with name:', argv.name) } const createBuilder = (yargs) => { yargs.positional('name',…
devboell
  • 1,180
  • 2
  • 16
  • 34
3
votes
0 answers

Prevent yargs from accepting invalid inputs

I've got a typescript program that I'm trying to use yargs with, but I'm having trouble getting yargs to correctly detect invalid commands: let test = yargs.command('test', ''); test.strict(); let args = test.parse(['fake', 'blah', 'test',…
Rob Watts
  • 6,866
  • 3
  • 39
  • 58
3
votes
1 answer

how to map multiple keys to aliases in yargs .alias

Yargs api says about .alias(key, alias): Optionally .alias() can take an object that maps keys to aliases. Each key of this object should be the canonical version of the option, and each value should be a string or an array of strings. I tried to…
Eran Or
  • 1,252
  • 15
  • 22
3
votes
2 answers

How do I specify a default subcommand in yargs?

I'm using yargs to create a build tool with subcommands for "build", "link", "clean", etc. I'd like to be able to type ./build.js with no arguments and invoke the "build" subcommand handler as a default. I was able to do it thusly: var argv = yargs …
Tedward
  • 193
  • 3
  • 6
3
votes
1 answer

Yargs documenting a flag

I was trying to figure out how to document and alias a param that takes no values with yargs What I want to do is alias -c to --compile and be able to document --compile. If --compile script sources -c I was expecting it to be something like this …
megawac
  • 10,953
  • 5
  • 40
  • 61
2
votes
1 answer

Property does not exist using yargs and typescript

I am trying to parse a command line with yargs in typescript and it doesn't work: import yargs from 'yargs'; const argv = yargs .option('label', { alias: 'l', describe: 'Execute bot with these labels', demandOption: false, type:…
Paul Exchange
  • 2,637
  • 3
  • 26
  • 33
2
votes
0 answers

How to define / get types of argv in command handler with yargs?

I am trying to create a CLI utility with Yargs but the types of argv in my command handlers are unknown. I installed @types/yargs as well but still cannot resolve the types. Any help would be greatly appreciated. I tried extending Yarg's…
ChrisGM
  • 33
  • 4
2
votes
1 answer

yargs giving `Missing args error` even though args are provided in typescript app

I have been breaking my head over this. I have looked at a lot of tutorials, not sure what am I doing wrong. Here's my sample test.ts import * as yargs from 'yargs'; const argv = yargs.options({ env: { alias: 'e', choices:…
Abhilasha
  • 357
  • 1
  • 5
  • 19
2
votes
2 answers

Node.js yargs package on ES modules

Yargs example: require('yargs') .scriptName("pirate-parser") .usage('$0 [args]') .command('hello [name]', 'welcome ter yargs!', (yargs) => { yargs.positional('name', { type: 'string', default: 'Cambi', describe:…
wmrisgood
  • 31
  • 2
2
votes
0 answers

yargs supports a minimum Node.js version of 12 - Jenkins

I have a problem with webdriver-io and jenkins. When I run my test cases on jenkins platform, I see an error message: yargs supports a minimum Node.js version of 12. Read our version support policy:…
Mat
  • 21
  • 1
  • 3
2
votes
0 answers

Why multiple commands in yargs are not working?

I am working on a CLI Project, where the user has to login before using any of its other commands. Below are the commands that the user will interact with. oms login -u username -p -a auth_url oms get -u url When I'm trying to see the help for oms…
Aditya
  • 21
  • 3
2
votes
1 answer

add default numerical value to optional argument with yargs

I have a cli script that accepts commandline parameters. For the pages parameter I would like the behaviour to be: > script.js -> pages parameter not set. don't process pages > script.js -p 100 -> pages parameter set with value 100: process 100…
marty
  • 61
  • 1
  • 6
2
votes
1 answer

yarn test fails with jasmine-ts yargs dependency

I am running yarn test to run my tests. I had to update some versions in my package.json file beforehand, so I deleted the yarn.lock file. Before removing the yarn.lock file, the tests pass just fine. Now, the tests fail with this error: TypeError:…
johnny_mac
  • 1,801
  • 3
  • 20
  • 48
1 2
3
9 10