I have the following commander command with several arguments:
var program = require('commander'); program .command('rename <id> [name]') .action(function() { console.log(arguments); }); program.parse(process.argv);
Using the application gives the following result:
$ node app.js 1 "Hello" { '0': '1', '1': { commands: [], options: [], _execs: [], _args: [ [Object] ], _name: 'rename', parent: { commands: [Object], options: [], _execs: [], _args: [], _name: 'app', Command: [Function: Command], Option: [Function: Option], _events: [Object], rawArgs: [Object], args: [Object] } } }
As you can see, the action receives the first argument ( <id> ) and program , but does not receive the second argument: [name] .
I tried:
- Create
[name] required argument. - Passing a name not entered into the tool from the command line.
- Simplifying my real application in the tiny reproducible program above.
- Using a variational argument for
name ( rename <id> [name...] ), but this leads to both 1 and Hello being assigned to the same array as the first parameter for the action, defeating the goal of having id .
What am I missing? Does the commander accept only one argument per command (doesn't look like this in the documentation)?
source share