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

Pass arguments to packaged electron application

We're using electron-packager to bundle up and distribute the front-end of our web application. We need to be able to pass in the host and port of the server to the electron front-end for connecting. When we launch via electron main.js --host blah…
DTI-Matt
  • 2,065
  • 9
  • 35
  • 60
5
votes
0 answers

Pass string with space using Yargs

I am using yargs to collect any arguments passed. My scenario is to be able to pass a string with spaces with double quotes just like this: ./nodeFile.js -n "my node module" But it actually takes "my as the argument value for yargs.argv.n and put…
amal
  • 321
  • 5
  • 14
4
votes
0 answers

How to test yargs application using Jest (Javascript/Typescript)

I already asked the question on Jest repository here. And also pushed a sample application here to reproduce the behavior. But for the sake of completeness here's the full story: Essentially it's like this (./parsers.ts): import yargs from…
Rad
  • 4,292
  • 8
  • 33
  • 71
4
votes
4 answers

How to make a typescript definition that depends on previous value?

See this code for example: var a a.set('my-custom-value',55) a. In line number 3, How I make the IDE to be aware to the value in line 2, and offer auto complete to a string the defined by the end-user who is using the library? I want that after I…
4
votes
0 answers

How can I define a shorthand alias for a boolean yargs option that negates the option?

Let's say I want to pass my (yargs-enabled) script a boolean option: ./foo --secure-but-slow=false secure-but-slow should default to true, so only users who know what they're doing choose the insecure option. However, it would be nice for power…
Sasgorilla
  • 2,403
  • 2
  • 29
  • 56
4
votes
3 answers

Using command line arguments with ReactJS

I'm wondering if it's possible to use command line arguments with ReactJS (not react-native). For example, is it possible to input a simple string and have it be saved as a variable so it can be displayed? The npm yargs module is the kind of thing…
Cyclicduck
  • 583
  • 1
  • 6
  • 11
4
votes
2 answers

How to use yargs array syntax with gulp?

Using array syntax of yargs with gulp throws errors. Here is my code: var argv = require("yargs") .array("modules") .argv; and using it like this: gulp taskname --modules m1 m2 Task 'm2' is not in your gulpfile How can I set an array using…
alisabzevari
  • 8,008
  • 6
  • 43
  • 67
3
votes
2 answers

Facing this error: TypeError: yargs.command is not a function

I am trying to run the yargs.command command. I tried running this code snippet : import yargs from "yargs"; yargs.command({ command: "list", describe: "List all commands", handler: function () { console.log("Listing all commands."); …
lone wolf
  • 85
  • 8
3
votes
2 answers

How to get yargs auto-complete working, when using --experimental-specifier-resolution=node

My objective is to write a CLI in Typescript/node.js, that uses --experimental-specifier-resolution=node, written in yargs with support for autocompletion. To make this work, I use this entry.sh file, thanks to this helpful SO anwswer (and the bin:…
DauleDK
  • 3,313
  • 11
  • 55
  • 98
3
votes
1 answer

Why are commands missing from this yargs script help page?

Can someone explain why the below script doesn't show the help for all commands? test.js [command] Commands: test.js list-spaces List spaces Options: --help Show help [boolean] --version …
Sandra Schlichting
  • 25,050
  • 33
  • 110
  • 162
3
votes
1 answer

yargs argv not working anymore after update to latest version

I had this code const argv = yargs .option("applyChanges", { alias: "a", description: "Apply the changes", type: "boolean" }) .help() .alias("help", "h").argv; const options = { applyChanges:…
sharkbait
  • 2,980
  • 16
  • 51
  • 89
3
votes
2 answers

Where can i find documentation for builder in yargs npm?

Does anyone know npm yargs very well? I am using this package for command line argument thing.. BUT I cannot find explanation for "builder". Where can i get this? yargs.command({ command: 'test', describe: 'testing a note', builder:{ …
klee214
  • 31
  • 1
  • 2
3
votes
2 answers

Yargs : access processed argv in fail function

I use yargs for a complexe command line (with subcommands via commandDir). I'd like to use the .fail(fn) to send an email every time the given command failed. The .fail(fn) is correctly triggered but I'd like to be able to have access to the args…
Morgan
  • 93
  • 1
  • 10
3
votes
3 answers

yargs demand one of builder option

How can I make require one of my options from builder object from command require('yargs') .usage('Usage: $0 [options]') .command( 'read', 'Read a note', { id: { demand: true, string: true }, …
ARIF MAHMUD RANA
  • 5,026
  • 3
  • 31
  • 58
3
votes
1 answer

Using Yargs inside Gulp

I'm working with yargs to pass arguments in a gulp command. I am having troubles checking the validity of the arguments and what shall happen if the flag is present or not. More specifically, here is my gulpfile.js: 'use strict'; var argv =…
Lucbug
  • 475
  • 6
  • 16
1
2
3
9 10