Skip to content

Commit

Permalink
Restore arguments order to pass to subcommands
Browse files Browse the repository at this point in the history
so that option parsing is done by the subcommand, which may have its own options.
Addressed case:
`cmd subcmd -o arg1 arg2` where `-o` is defined on the subcommand
was passing an args array like `[ arg2, -o, arg1 ]` to the subcommand
  • Loading branch information
maxlath committed Dec 16, 2017
1 parent fefda77 commit 1297ae6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions index.js
Expand Up @@ -486,15 +486,16 @@ Command.prototype.parse = function(argv) {
}

if (this._execs[name] && typeof this._execs[name] != "function") {
return this.executeSubCommand(argv, args, parsed.unknown);
this.args = args = argv.slice(2)
return this.executeSubCommand(argv, args);
} else if (aliasCommand) {
// is alias of a subCommand
args[0] = aliasCommand._name;
return this.executeSubCommand(argv, args, parsed.unknown);
this.args = args = [ aliasCommand._name ].concat(argv.slice(3))
return this.executeSubCommand(argv, args);
} else if (this.defaultExecutable) {
// use the default subcommand
args.unshift(this.defaultExecutable);
return this.executeSubCommand(argv, args, parsed.unknown);
this.args = args = [ this.defaultExecutable ].concat(argv.slice(3))
return this.executeSubCommand(argv, args);
}

return result;
Expand All @@ -509,9 +510,7 @@ Command.prototype.parse = function(argv) {
* @api private
*/

Command.prototype.executeSubCommand = function(argv, args, unknown) {
args = args.concat(unknown);

Command.prototype.executeSubCommand = function(argv, args) {
if (!args.length) this.help();
if ('help' == args[0] && 1 == args.length) this.help();

Expand Down

0 comments on commit 1297ae6

Please sign in to comment.