Skip to content
Myr

Merge branch 'pr/545'

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

authored by zhiyelee · committed by zhiyelee · parents c86ba2a, ad46a4d · Browse files · 6 files+94 added−10 removed
This commit

State

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

Diff stats

6 files+94 added−10 removed

  • tests:+69 added−4 removed
  • other:+25 added−6 removed

6 files+94 added−10 removed

modified:examples/pm+3 added-3 removed
2 unmodified lines
3var program = require('..');45program6 .version('0.0.1')7 .command('install [name]', 'install one or more packages')8 .command('search [query]', 'search with optional query')7 .command('install [name]', 'install one or more packages').alias('i')8 .command('search [query]', 'search with optional query').alias('s')9 .command('list', 'list packages installed')10 .command('publish', 'publish the package')10 .command('publish', 'publish the package').alias('p')11 .parse(process.argv);1213// here .command() is invoked with a description,14// and no .action(callback) calls to handle sub-commands.
13 unmodified lines
modified:test/fixtures/pm+4 added-4 removed
2 unmodified lines
3var program = require('../../');45program6 .version('0.0.1')7 .command('install [name]', 'install one or more packages')8 .command('search [query]', 'search with optional query')9 .command('cache', 'actions dealing with the cache')7 .command('install [name]', 'install one or more packages').alias('i')8 .command('search [query]', 'search with optional query').alias('s')9 .command('cache', 'actions dealing with the cache').alias('c')10 .command('list', 'list packages installed')11 .command('publish', 'publish or update package')11 .command('publish', 'publish or update package').alias('p')12 .command('default', 'default command', {noHelp: true, isDefault: true})13 .parse(process.argv);
added:test/test.command.alias.help.js+20 added
added:test/test.command.executableSubcommandAlias.help.js+17 added
added:test/test.command.executableSubcommandAlias.js+28 added
modified:index.js+22 added-3 removed
457 unmodified lines
458 var result = this.parseArgs(this.args, parsed.unknown);459460 // executable sub-commands461 var name = result.args[0];462463 var aliasCommand = null;464 // check alias of sub commands465 if (name) {466 aliasCommand = this.commands.filter(function(command) {467 return command.alias() === name;468 })[0];469 }470471 if (this._execs[name] && typeof this._execs[name] != "function") {472 return this.executeSubCommand(argv, args, parsed.unknown);473 } else if (aliasCommand) {474 // is alias of a subCommand475 args[0] = aliasCommand._name;476 return this.executeSubCommand(argv, args, parsed.unknown);477 } else if (this.defaultExecutable) {478 // use the default subcommand466 args.unshift(name = this.defaultExecutable);479 args.unshift(this.defaultExecutable);480 return this.executeSubCommand(argv, args, parsed.unknown);481 }482483 return result;
378 unmodified lines
862 * @api public863 */864865Command.prototype.alias = function(alias) {853 if (0 == arguments.length) return this._alias;854 this._alias = alias;866 var command = this;867 if(this.commands.length !== 0) {868 command = this.commands[this.commands.length - 1]869 }870871 if (arguments.length === 0) return command._alias;872873 command._alias = alias;874 return this;875};876877/**
252 unmodified lines