-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with nested commands #386
Comments
I'm not using nested commands but still I'm facing this Programvar program = require('commander');
program
.version(require('../package.json').version)
.usage('<input> <output> [vars...]')
.arguments('[input] [output]')
.action(function(input, output, vars){
console.log('input', input);
console.log('output', output);
console.log('vars', vars);
})
.parse(process.argv); Execution$ program a b c=1 d=2 e=3 Outputinput -> a
output -> b
vars -> { commands: [],
options:
[ { flags: '-V, --version',
required: 0,
optional: 0,
bool: true,
short: '-V',
long: '--version',
description: 'output the version number' } ],
_execs: [],
_allowUnknownOption: false,
_args:
[ { required: false, name: 'input', variadic: false },
{ required: false, name: 'output', variadic: false } ],
_name: 'condilation',
Command: [Function: Command],
Option: [Function: Option],
_version: '1.0.0',
_events: { version: [ [Function], [Function] ], '*': [Function] },
_usage: '<input> <output> [vars...]',
rawArgs:
[ 'node',
'/this/is/the/script/path',
'a',
'b',
'x=1',
'y=2',
'z=3' ],
args: [ 'a', 'b', [Circular], 'y=2', 'z=3' ] } ConclusionNot sure if I should ever skip this |
Having the same issue. Wondering what is the solution? I also see: variadic: false... which is not mentioned in the example code. |
Hey @foxx, @arboleya, @mattwilliams For nested commands I found the following to work well for me ->
The example above shows a program that has a root command with two subcommands.Doing it this way allows for independent configuration/options for subcommands and root command. The reason it works is because CommanderJS is creating a new command for each sub command and root command. Usages Execute root command:
P.S. Hope this is what you are looking for :) |
Working on this currently. |
v4.0.0-0 prerelease published: #1067 |
v4.0.0 has been released with a fix for program.args which was getting the command appended (matching the arguments passed to the action handler). |
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 asrawArgs
seems to contain the correct items. Had a look atparseOptions
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
Output
The text was updated successfully, but these errors were encountered: