Skip to content
Myr

Merge branch 'feature_specify_subcommand' of https://github.com/abetomo/commander.js into abetomo-feature_specify_subcommand

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

authored by John Gee · committed by John Gee · parents 631dfdc, 5f8ef7b · Browse files · 3 files+62 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

3 files+62 added−2 removed

  • tests:+46 added−0 removed
  • other:+16 added−2 removed

3 files+62 added−2 removed

modified:test/fixtures/pm+2 added
9 unmodified lines
10 .command('list', 'list packages installed')11 .command('listen', 'listen for supported signal events').alias('l')12 .command('publish', 'publish or update package').alias('p')13 .command('default', 'default command', {noHelp: true, isDefault: true})14 .command('specifyInstall', 'specify install subcommand', {subcommand: 'pm-install'})15 .command('specifyPublish', 'specify publish subcommand', {subcommand: 'pm-publish'})16 .parse(process.argv);
added:test/test.command.executableSubcommandSpecifySubcommand.js+44 added
modified:index.js+16 added-2 removed
180 unmodified lines
181 this._execs[cmd._name] = true;182 if (opts.isDefault) this.defaultExecutable = cmd._name;183 }184 cmd._noHelp = !!opts.noHelp;185 cmd._specifySubcommand = opts.subcommand;186 this.commands.push(cmd);187 cmd.parseExpectedArgs(args);188 cmd.parent = this;189
296 unmodified lines
486 return command.alias() === name;487 })[0];488 }489490 var specifySubcommand = null;491 if (name) {492 specifySubcommand = this.commands.filter(function(command) {493 return command._name === name && command._specifySubcommand != null;494 })[0];495 }496497 if (specifySubcommand) {498 return this.executeSubCommand(argv, args, parsed.unknown, specifySubcommand._specifySubcommand);489 if (this._execs[name] && typeof this._execs[name] !== 'function') {499 } else if (this._execs[name] && typeof this._execs[name] !== 'function') {500 return this.executeSubCommand(argv, args, parsed.unknown);501 } else if (aliasCommand) {502 // is alias of a subCommand503 args[0] = aliasCommand._name;
12 unmodified lines
516 *517 * @param {Array} argv518 * @param {Array} args519 * @param {Array} unknown520 * @param {String} specifySubcommand521 * @api private522 */523513Command.prototype.executeSubCommand = function(argv, args, unknown) {524Command.prototype.executeSubCommand = function(argv, args, unknown, specifySubcommand) {525 args = args.concat(unknown);526527 if (!args.length) this.help();528 if (args[0] === 'help' && args.length === 1) this.help();
7 unmodified lines
536 // executable537 var f = argv[1];538 // name of the subcommand, link `pm-install`539 var bin = basename(f, path.extname(f)) + '-' + args[0];540 if (specifySubcommand != null) {541 bin = specifySubcommand;542 }543544 // In case of globally installed, get the base dir where executable545 // subcommand file should be located at546 var baseDir;
701 unmodified lines