Questions tagged [yargs]

Use this tag for questions relating to the Yargs node.js library.

112 questions
32
votes
7 answers

Gulp task with different source depending on arguments

I want to accomplish something simple using gulp. I want to write a generic method to move files to an output directory from a particular source directory. pretend we have something like so var args = require('yargs'); function…
jth41
  • 3,542
  • 8
  • 50
  • 105
16
votes
3 answers

npm script pass parameters/arguments to node script using yargs

Is it possible to call out to retrieve a key from yargs when using as a npm script argument? User types in the OSX terminal: npm run scaffold --name=blah which executes in package.json: "scaffold" : "node ./scaffold/index.js -- " This results in…
Simon
  • 1,716
  • 5
  • 26
  • 48
10
votes
2 answers

How to parse commandline args with yargs in typescript

Here is what I tried (code adapted the code from the example in the yargs github readme): // main.ts import {Argv} from "yargs"; console.info(`CLI starter.`); function serve(port: string) { console.info(`Serve on port…
qed
  • 19,750
  • 16
  • 99
  • 168
9
votes
1 answer

Cannot find module 'yargs' error while deploying node.js app to google cloud platform

I am trying to deploy my node.js application to google cloud and my package.json includes the yargs as dependencies. And when I deploy the app to google cloud and after that I am getting error can't find module yargs in google cloud platform…
user10742206
8
votes
2 answers

I am trying to run yargs command, and it is not working

I am running: node app.js add And my code is: const yargs = require('yargs'); yargs.command({ command:'add', describe:'Adding command', handler:function(){ console.log('Adding notes'); }, }) But nothing printed on the…
Sugumar Venkatesan
  • 3,536
  • 4
  • 30
  • 61
7
votes
1 answer

Yargs: Call existing command in command handler

I'm trying to implement a restart command using yargs. I already implemented the start and stop commands and all I want to do now, is call these existing commands inside the restart command. Unfortunately it does not work by simply using…
6
votes
1 answer

What is the difference between command and option in [yargs]

I am using yargs for getting CLI arguments. I want to know the difference between command and option. const argv = yargs .command( 'add', 'Add a new note', { title: titleOptions, body: bodyOptions }) .argv; And const argv =…
thenm
  • 151
  • 2
  • 8
6
votes
1 answer

yargs .check() error handling

I'm using yargs to validate cli arguments for a data-loading helper lib. I want to be able to check that a file exists before allowing the script to run, which I do with fs.accessSync(filename, fs.R_OK);. However, if the file does not exist, the…
abenrob
  • 656
  • 8
  • 20
6
votes
1 answer

Setup command line completion with yargs

I'm creating a script with node JS and want to enable async command line completion with yargs. The completion section of the yargs documentation says: "concat the generated script to your .bashrc or .bash_profile" But I don't see any information…
Shanimal
  • 10,987
  • 7
  • 58
  • 71
5
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
  • 1,947
  • 5
  • 32
  • 57
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 to correctly unit test yargs in typescript

There are 2 points that I need to be explained - How to reset yargs without using deprecated .reset() method; (.global() method instead, but how ??) - how do I pass in the command line to yargs as typed in by the user Given the following…
Plastikfan
  • 2,722
  • 5
  • 32
  • 47
4
votes
1 answer

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
  • 513
  • 1
  • 5
  • 10
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
  • 7,178
  • 6
  • 38
  • 60
3
votes
3 answers

Yargs not working when using import in Node.js

I'm new to Node.js and I'm learning some basics now. I'm trying to use some typescript code to convert into .js code later. I wrote this simple code to test import * as fs from 'fs' const argv = require('yargs') …
Thauany Moedano
  • 171
  • 1
  • 11
1
2 3 4 5 6 7 8