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.
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);
$ 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' ]
This seems to also be affecting another user on SO.
The output of
options.parent.argsseems to be malformed, the second element in the list appears to be a circular reference to itself, where asrawArgsseems to contain the correct items. Had a look atparseOptionsin 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
Output