minor update
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by zhiyelee · committed by zhiyelee · parent afd6f49 · Browse files · 4 files·+20 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+20 added−22 removed
- tests:+3 added−11 removed
- other:+17 added−11 removed
Provenance
- Commit
ad46a4d- Tree
b2116aa- Author
zhiyelee <zhiyelee@gmail.com>- Committer
zhiyelee <zhiyelee@gmail.com>- Parent
afd6f49
4 files changed+20 added−22 removed
modified:test/fixtures/pm+1 added-1 removed
5 unmodified lines6 .version('0.0.1')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').alias('l')10+ .command('list', 'list packages installed')11 .command('publish', 'publish or update package').alias('p')12 .command('default', 'default command', {noHelp: true, isDefault: true})13 .parse(process.argv);modified:test/test.command.executableSubcommandAlias.help.js+1 added-1 removed
9 unmodified lines1011121314141516179 unmodified linesexec(bin + ' help', function (error, stdout, stderr) { stdout.should.containEql('install|i'); stdout.should.containEql('search|s'); stdout.should.containEql('cache|c'); stdout.should.containEql('list|l'); stdout.should.containEql('list'); stdout.should.containEql('publish|p'); stdout.should.not.containEql('pm|');});modified:test/test.command.executableSubcommandAlias.js+1 added-9 removed
1234565891011121367895 unmodified lines151617182719202122235 unmodified linesvar exec = require('child_process').exec , path = require('path') , should = require('should');
var bin = path.join(__dirname, './fixtures/pm')// not existexec(bin + ' l', function (error, stdout, stderr) { //stderr.should.equal('\n pm-list(1) does not exist, try --help\n\n'); // TODO error info are not the same in between <=v0.8 and later version should.notEqual(0, stderr.length);});
// success caseexec(bin + ' i', function (error, stdout, stderr) { stdout.should.equal('install\n');5 unmodified lines});
// spawn EACCESexec(bin + ' s', function (error, stdout, stderr) { // TODO error info are not the same in between <v0.10 and v0.12 // error info are not the same in between <v0.10 and v0.12 should.notEqual(0, stderr.length);});
// when `bin` is a symbol link for mocking global install5 unmodified linesmodified:index.js+17 added-11 removed
457 unmodified lines458 var result = this.parseArgs(this.args, parsed.unknown);459 460 // executable sub-commands461 var name = result.args[0];462- var aliasCommand = this.commands.filter(function(command) {463- var _alias = command.alias();464- return _alias !== undefined && _alias === name;465- })[0];462+463+ 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+ }470+471 if (this._execs[name] && typeof this._execs[name] != "function") {472 return this.executeSubCommand(argv, args, parsed.unknown);468- } else if (aliasCommand !== undefined) {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 subcommand473- args.unshift(name = this.defaultExecutable);479+ args.unshift(this.defaultExecutable);480 return this.executeSubCommand(argv, args, parsed.unknown);481 }482 483 return result;378 unmodified lines862 * @api public863 */864 865 Command.prototype.alias = function(alias) {860- var command = undefined;861- if(this.commands.length == 0) {862- command = this;863- } else {866+ var command = this;867+ if(this.commands.length !== 0) {868 command = this.commands[this.commands.length - 1]869 }870+866- if (0 == arguments.length) return command._alias;871+ if (arguments.length === 0) return command._alias;872+873 command._alias = alias;874 return this;875 };876 253 unmodified lines