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
2
votes
2 answers

yargs.command is not working (error msg: yargs.command is not a function)

I am trying to create yargs command, when I run the app I get an error. When I run the following: node app.js add on my node.js code: const yargs = require('yargs') yargs.command({ command:'add', describe:'Adding command', …
Ahmed Salah
  • 31
  • 1
  • 3
2
votes
1 answer

I'm getting yargs.methodName is not a function with all yargs methods using ES6 imports in NodeJS without Babel

So, I'm doing a nodejs tutorial, but the tutorial isn't updated to ES6 and I just wanted to update the code as I go along. I get the program to run just fine using require('yargs'), but keep getting yargs.command, yargs.argv, etc. is not a function.…
Ctcoleman
  • 71
  • 7
2
votes
1 answer

Asking the user to confirm before executing the code using Yargs

Using yargs is it possible for the user of the CLI to specify which command they want to call with the arguments and then the CLI replies with the following message before running the code: Are you sure you want to execute this code on environment X…
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
2
votes
1 answer

How to resolve white-source security issue for npm libraries

White-source has reported high security issue with following libraries for yargs-parser for my repo: 1. build-angular-0.13.8.tgz (Root Library) node-sass-4.11.0.tgz sass-graph-2.2.4.tgz yargs-7.1.0.tgz …
Anand Gargate
  • 479
  • 5
  • 16
2
votes
1 answer

Optional argument to option with yargs

I am trying to build a command-line interface with yargs, where one option takes an (optional!) argument: const cli = yargs .array('keyword') .option('keyword', { alias: 'k', type: 'string', describe: 'add additional keyword or clear…
Guido Flohr
  • 1,871
  • 15
  • 28
2
votes
1 answer

Argument escaping not interpreted correctly when running node.js script from Windows PowerShell

Given the following script: const yargs = require('yargs'); const argv = yargs .usage('Usage: $0 [--whatIf]') .alias('d', 'directory') .alias('wi', 'whatIf') .nargs('d', 1) .describe('d', 'alphabetize…
Casey
  • 3,307
  • 1
  • 26
  • 41
2
votes
0 answers

How to give aliases to positional arguments of a command with yargs

I am using yargs to build a command line application with node. One of my commands are as follows: exports.command = 'website [prod]' exports.aliases = ['w'] exports.desc = 'create new website with type at url for…
Janpan
  • 2,164
  • 3
  • 27
  • 53
2
votes
2 answers

Migrate from require to import es6 with yargs

I am doing some code samples with node.js and yargs and I am trying to access yargs.command and yargs.version which I easily had access to with require. But when I use import with the line: import * as yargs from 'yargs'; It returns an error saying…
tony_h
  • 95
  • 2
  • 10
2
votes
1 answer

How would I configure yargs to take a single input file and optional output file?

I'm playing with yargs as would like to configure the following command line options: Usage: myapp [destination file] No options, no commamnds, etc. Just takes a file path to read from and an optional one to write to. What's the yarg…
dommer
  • 19,610
  • 14
  • 75
  • 137
2
votes
1 answer

does yargs have a hook i can run before each command?

I need to run some code before each command runs, using the name of the command. i was unable to find anything in the yargs api docs. specifically, i want to delete the cache created by each of my commands. for example the command foo, creates a…
brewster
  • 4,342
  • 6
  • 45
  • 67
1
vote
1 answer

How to create yargs default response when no command selected

I have created a CLI with yargs. It has a series of nested commands. All the commands work nicely, but I also want to have a welcome/info message when no command is given or if a command that does not exist is supplied. I have been unable to get…
APW
  • 420
  • 4
  • 15
1
vote
0 answers

read and write file using yargs

I have a .log file as input and I want to covert this log file to .json format and then write to an output file. For doing this operation I have used yargs package. Here is the code I am trying: import yargs from 'yargs' import fs from 'fs' //…
Angels
  • 325
  • 4
  • 15
1
vote
0 answers

yargs argv do not contain command and params

I am using yargs in a CLI application. In Windows platform (development environment), I am able to invoke the commands but when I pack and run it on Amazon Linux the yargs argv is not containing the command and parameters. I am packaging the…
S7H
  • 1,421
  • 1
  • 22
  • 37
1
vote
1 answer

How to distinguish empty command case and default command in yargs?

I want to write a little CLI tool using yargs and typescript. The first goal is to run the program(I will call it something in this question) when the empty command and --input is given.(e.g. something --input="../hello.there"). I used the default…
Hyeonseo Kim
  • 324
  • 3
  • 15
1
vote
1 answer

How to structure one of many commands in yargs?

I have read the yargs documetation multiple times, but can't figure out this one. Here are my requirements: My CLI should provide two commands: cmd1 and cmd2. The user must specify one of these two commands, otherwise the CLI must print a help…
Naresh
  • 23,937
  • 33
  • 132
  • 204