-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Problem with nested commands #386
Copy link
Copy link
Closed
Milestone
Description
This seems to also be affecting another user on SO.
The output of options.parent.args seems to be malformed, the second element in the list appears to be a circular reference to itself, where as rawArgs seems to contain the correct items. Had a look at parseOptions in the source but the code isn't very clear in terms of documented logic.
At the very least this would be worthy of a docs update, but as I'm not too sure why the problem is happening, I'm reluctant to sent a PR fix.
Thoughts?
Sample code
var program = require('commander');
program
.version(version)
.option('-v, --verbose', 'Enable verbose output')
.usage('[options] [command]')
program
.command('runserver <args>')
.description('run websockets server')
.action(function(env, options){
console.log(options.parent.rawArgs);
console.log(options.parent.args);
});
program.parse(process.argv);
Output
$ node bin/boards-server.js -v runserver 1 2 3 4 5 6 7 8 9
[ 'node',
'/vagrant/server/bin/boards-server.js',
'-v',
'runserver',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9' ]
[ '1',
{ commands: [],
options: [],
_execs: [],
_allowUnknownOption: false,
_args: [ [Object] ],
_name: 'runserver',
parent:
{ commands: [Object],
options: [Object],
_execs: [],
_allowUnknownOption: false,
_args: [],
_name: 'boards-server',
Command: [Function: Command],
Option: [Function: Option],
_version: <Buffer 30 2e 30 2e 31>,
_events: [Object],
_usage: '[options] [command]',
rawArgs: [Object],
verbose: true,
args: [Circular] },
_description: 'run websockets server' },
'3',
'4',
'5',
'6',
'7',
'8',
'9' ]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels