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
2
votes
1 answer

ORA Spinner stops on CLI with Inquirer.js

Don't know what to title the question but I will try my best to convey in the rest of the question. I am developing a CLI which first prompt user for a few questions and clone a repository based on the answers. Example: Frontend Framework: [x] Vue […
2
votes
1 answer

commander.js simple use case: one single file argument

I've seen that most people use commander npm package when having to deal with command-line parsing. I would like to use it as well because it seems to have pretty advanced functionality (e.g. commands, help, option flags, etc). However, for the…
knocte
  • 16,941
  • 11
  • 79
  • 125
2
votes
2 answers

Commander throws error for command with description

Here is a simple example of adding command in nodejs using commander: 'use strict'; const {Command} = require('commander'); const run = () => { const program = new Command(); console.log('CMD'); program.command('cmd [opts...]') …
Rostislav Shtanko
  • 704
  • 2
  • 9
  • 30
2
votes
2 answers

Proper way to make callbacks async by wrapping them using `co`?

It is 2016, Node has had nearly full ES6 support since v4, and Promises have been around since 0.12. It's time to leave callbacks in the dust IMO. I'm working on a commander.js-based CLI util which leverages a lot of async operations - http requests…
Aksel Gresvig
  • 715
  • 1
  • 9
  • 21
1
vote
0 answers

Dynamically create subcommands with options using Commander.js

I am trying to create a CLI that can dynamically create subcommands with options. I have a main program named 'dashboard'. I want to create 'login' and a 'logout' subcommands that have options. I can't seem to get the subcommand options to run. It…
1
vote
0 answers

Node Commander.js catching options passed to Mocha when running tests

I've recently introduced commander.js to a project and use it in various scripts to parse CLI arguments. I'll give one example of where it's been used: const { program } = require('commander'); program .description('Import customers and…
1
vote
1 answer

Where do compiled NodeJs apps read the dotenv file from at execute time?

I am writing a commanderjs app, that uses dotenv. The app is that is compiled using pkg . I have compiled the app for linux and moved the binary to /usr/local/bin, for it to be available on my PATH. I am running the app from a shell script in…
StuperUser
  • 10,555
  • 13
  • 78
  • 137
1
vote
1 answer

How to process options before commands in commander.js?

This is my code: const {program} = require('commander'); program .option('--foo') .command('bar').action((str, opts) => { console.log('bar!'); }) program.parse(); if (program.opts().foo) { console.log('foo!'); } I run it like node…
yegor256
  • 102,010
  • 123
  • 446
  • 597
1
vote
1 answer

Find the type of the file/folder passed to the CLI in nodejs

I'm creating a CLI app and using commander to process the commands entered by the user. program .option('-i , --index', 'file ') // option for adding a file/folder const options = program.opts(); if(option.index){ // do sth } And the user can enter…
NateR
  • 85
  • 9
1
vote
1 answer

Short help and long help in commander

I am using commander package as CLI parser. commander .command('command1 ' ) .description('description 1 goes here') .command('command2 ' ) .description('description 2 goes here') Is there a way to…
Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136
1
vote
2 answers

Is there a way to overwrite commander js usage information?

I want to completely overwrite usage information from commander js: Usage: name [options] Options: -V, --version output the version number -h, --help display help for command to create my own. However, I cannot find option to do that.
papryk
  • 442
  • 4
  • 14
1
vote
1 answer

Nodejs - passing commander arguments to forever-monitor child process

I have this node cli script #!/usr/bin/env node const path = require('path'); const forever = require('forever-monitor'); const script = path.format({dir: __dirname, base: 'pager.js'}); const chalk = require('chalk'); const commander =…
1
vote
0 answers

webpack Error: Cannot find module 'commander'

I get an error when I run in the CLI ./node_modules/.bin/webpack index.js --mode=development Here's the error: node:internal/modules/cjs/loader:903 throw err; ^ Error: Cannot find module 'commander' Require stack: -…
1
vote
0 answers

Commands for Commander not returning data

I'm trying to build a node cli to keep an organized planner. I have 'locate' command that goes to the options for commands either 'find' or 'list', but no data is being shown even though the mongoose functions are working correctly. 'todo locate…
Tripiod8
  • 99
  • 6
1
vote
1 answer

passing string with spaces to node cli-parser

var minimist = require("minimist") const a = minimist(`executable --param "a b"`.split(' ')) console.log(a) https://runkit.com/embed/57837xcuv5v0 actual output: Object {_: ["executable", "b\""], param: "\"a"} expected output: Object {_:…
Stav Alfi
  • 13,139
  • 23
  • 99
  • 171