Skip to content
Myr

add support for sub-commands to co-exist with the original command

Before adoption: this commit came in with the history the project adopted, so no landing records it.

before this lame hack you were basically required to make the original command do nothing but delegate to other sub-commands

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 1c6ea15 · Browse files · 1 file+5 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−2 removed

  • other:+5 added−2 removed

1 file+5 added−2 removed

modified:index.js+5 added-2 removed
89 unmodified lines
9091function Command(name) {92 this.commands = [];93 this.options = [];94 this._execs = [];95 this._args = [];96 this._name = name;97}98
56 unmodified lines
155 var args = name.split(/ +/);156 var cmd = new Command(args.shift());157 if (desc) cmd.description(desc);158 if (desc) this.executables = true;159 if (desc) this._execs[cmd._name] = true;160 this.commands.push(cmd);161 cmd.parseExpectedArgs(args);162 cmd.parent = this;163 if (desc) return this;
211 unmodified lines
375 var args = this.args = parsed.args;376 377 var result = this.parseArgs(this.args, parsed.unknown);378377 // executable sub-commands, skip .parseArgs()378 if (this.executables) return this.executeSubCommand(argv, args, parsed.unknown);379 // executable sub-commands380 var name = result.args[0];381 if (this._execs[name]) return this.executeSubCommand(argv, args, parsed.unknown);382383 return result;384};385
775 unmodified lines