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.
Questions tagged [yargs]
143 questions
33
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,808
- 9
- 59
- 109
19
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
- 2,484
- 6
- 35
- 54
15
votes
3 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
- 22,298
- 21
- 125
- 196
14
votes
2 answers
How to run node.js cli with experimental-specifier-resolution=node?
Our team has built a small CLI used for maintenance. The package.json specifies a path for with the bin property, and everything works great; "bin": { "eddy": "./dist/src/cli/entry.js"}
Autocompletion is achived by using yargs@17.0.1. However we…

DauleDK
- 3,313
- 11
- 55
- 98
11
votes
4 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
- 4,019
- 8
- 46
- 77
11
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
11
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
- 878
- 10
- 23
9
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
- 201
- 4
- 9
8
votes
2 answers
How to implement multiple subcommands with Yargs?
I've been trying and trying, but just couldn't digest Yargs' docs.
I need to create a set of commands/subcommands:
~$framework generate routed-module ModuleOne ModuleTwo ModuleThree --animation-style=bounce-up
//would call a handler with:
{…

Daniel Birowsky Popeski
- 8,752
- 12
- 60
- 125
7
votes
0 answers
How to import file from npm package that is not part of package.json exports
I'm trying to import the content of a file that is not listed as an export by it's package's package.json file. What the library (yargs) suggests to do is to import the file through something like unpkg:
import Yargs from…

Alam Téllez
- 178
- 9
7
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
- 3,674
- 7
- 39
- 54
7
votes
5 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
- 551
- 2
- 8
- 21
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…

Marcel Pociot
- 118
- 6
7
votes
6 answers
Yargs help not displaying all the help options
I am using yargs to add command line options for the arguments passed to the script. When i issue the help command along with the script name, It does not display the help for add parameter.
const yargs=require('yargs');
const argv=…

ryan
- 694
- 9
- 23
7
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
- 11,517
- 7
- 63
- 76