Questions tagged [node-commander]

Commander is a popular command-line arguments parser for Node.js. Use this tag for questions about using the Commander npm package.

Commander is a popular command-line arguments parser for Node.js. You specify the options and commands and command-arguments in code, and Commander does the parsing of the command-line arguments and help generation and error detection.

Use this tag for questions about using the Commander npm package.

92 questions
27
votes
3 answers

Node js commander args returns true instead the value

I want to create a script with node and node commander and when i try to grab the values of my args i get the value true instead the value itself. For example if i write this in terminal: node myfile.js -s somefile -d test var program =…
user4207046
23
votes
2 answers

create nodejs cli select/options menu

How do you create an arrow-key menu list? I'm looking for something like after entering in eslint init or create-react-app ? (see images below) ESlint yeoman Searching around to find ways to create a CLI, I found NodeJS to be an option…
Chance Smith
  • 1,211
  • 1
  • 15
  • 32
22
votes
3 answers

Unnamed parameter with commander.js (positional arguments)

I am currently taking a look at commander.js as I want to implement a CLI using Node.js. Using named parameters is easy, as the example of a "pizza" program shows: program .version('0.0.1') .option('-p, --peppers', 'Add peppers') .option('-P,…
Golo Roden
  • 140,679
  • 96
  • 298
  • 425
13
votes
2 answers

commander.js : how to specify required cli argument

I'm using commander.js package for parsing command-line arguments: I'd like to make a flag non-optional, the API and tests in the git repo loosely mention making a flag required, but I usually need to be hit over the head with instructions. Is it…
asking
  • 1,435
  • 3
  • 13
  • 21
10
votes
3 answers

Commander.js display help when called with no commands

I'm using commander.js to write a simple node.js program that interacts with an API. All calls require the use of subcommands. For example: apicommand get Is called as follows: program .version('1.0.0') .command('get [accountId]') …
toddg
  • 2,863
  • 2
  • 18
  • 33
9
votes
2 answers

Use commander in typescript

I try to use commander in typescript and I could like to give a proper type to my cli. So I start with this code: import * as program from "commander"; const cli = program .version("1.0.0") .usage("[options]") .option("-d, --debug", "activate…
Louis Roché
  • 876
  • 1
  • 7
  • 19
7
votes
2 answers

NodeJS Commander structured subcommands

I am new to commander and I am trying to achieve a command tree like this: |- build | |- browser (+ options) | |- cordova (+ options) | |- no subcommands, just options |- config | |- create (+ options) Is it possible to split these…
Lehks
  • 2,582
  • 4
  • 19
  • 50
6
votes
2 answers

Node.js commander with optional+variadic arguments

Please help me get node's commander module to parse arguments the way I want. I'm looking to upload a list of files to a named database. There is a default database name, so the user shouldn't need to include a database parameter. I'd like this…
Gershom Maes
  • 7,358
  • 2
  • 35
  • 55
4
votes
1 answer

Nested commands with commander

I have the following code export const program = new Command(); program.version('0.0.1'); program .command('groups') .command('create') .action(() => console.log('creating')) .command('delete') .action(() =>…
AngularDebutant
  • 1,436
  • 5
  • 19
  • 41
4
votes
1 answer

How to use commander.js command through npm command

I'm using commander.js command like this ./index.js --project mono --type item --title newInvoice --comments 'Creates an invoice' --write, Now I'm using the command through npm run item newInvoice by setting some options in package.json file like…
Bablu Ahmed
  • 4,412
  • 5
  • 49
  • 64
4
votes
2 answers

Nodejs program doesn't terminate

This program will not terminate in the console, I have to use Ctrl-C. Documentation does not give any clues. Tried various things such as Return but just can't get it to terminate, it just hangs in the console. The last thing in the console is 'now…
Nepomuk
  • 55
  • 1
  • 5
3
votes
2 answers

How to convert Node.js command line app to single executable?

I built simple command line application using commander.js for Node.js platform. Now I want to compile it to simple exe file, Which I can execute directly. Means I want single executable file for complete application This is my application…
ssp singh
  • 152
  • 1
  • 14
3
votes
1 answer

Command line interface with Node.js

I am creating command line interface by using node.js. It has login feature and after login, needs to show output based on user selection from list. Problem i'm facing is it exits from the node after first result. It's asking login again. It should…
iLaYa ツ
  • 3,941
  • 3
  • 32
  • 48
3
votes
2 answers

Commander.js collect multiple options always include default

I'm using commander.js to parse the command line args and I'm trying to collect an optional param that can appear multiple times and it always returns the options I set plus the default one. function collect (val, memo) { memo.push(val); …
borgespires
  • 170
  • 1
  • 2
  • 11
2
votes
1 answer

args of short flag and long flag are parsed differently in commander module node js

program .command("split") .description("Split a string into substrings and display as an array") .argument("", "string to split") .option("--first", "display just the first substring") .option("-s ,--separator ", "separator…
1
2 3 4 5 6 7