Skip to content
Myr

Merge pull request #210 from tandrewnichols/add-alias

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

Added alias feature

authored by Randall Koutnik · committed by Randall Koutnik · parents ebdd789, e00c4ca · Browse files · 3 files+39 added−7 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+39 added−7 removed

  • tests:+7 added−0 removed
  • other:+32 added−7 removed

3 files+39 added−7 removed

modified:examples/deploy+1 added
22 unmodified lines
23 });2425program26 .command('exec <cmd>')27 .alias('ex')28 .description('execute the given remote cmd')29 .option("-e, --exec_mode <mode>", "Which exec mode to use")30 .action(function(cmd, options){31 console.log('exec "%s" using %s mode', cmd, options.exec_mode);
15 unmodified lines
modified:test/test.options.commands.js+7 added
modified:index.js+31 added-7 removed
209 unmodified lines
210 */211212Command.prototype.action = function(fn){213 var self = this;214 this.parent.on(this._name, function(args, unknown){214 var listener = function(args, unknown){215 // Parse any so-far unknown options216 args = args || [];217 unknown = unknown || [];218
27 unmodified lines
246 args.push(self);247 }248249 fn.apply(this, args);250 });250 };251 this.parent.on(this._name, listener);252 if (this._alias) this.parent.on(this._alias, listener);253 return this;254};255256/**
418 unmodified lines
675 return this;676};677678/**679 * Set an alias for the command680 *681 * @param {String} alias682 * @return {String|Command}683 * @api public684 */685686Command.prototype.alias = function(alias){687 if (0 == arguments.length) return this._alias;688 this._alias = alias;689 return this;690};691692/**693 * Set / get the command usage `str`.694 *695 * @param {String} str696 * @return {String|Command}
69 unmodified lines
766 ? '<' + arg.name + '>'767 : '[' + arg.name + ']';768 }).join(' ');769754 return pad(cmd._name770 return cmd._name771 + (cmd._alias772 ? '|' + cmd._alias773 : '')774 + (cmd.options.length775 ? ' [options]'757 : '') + ' ' + args, 22)776 : '') + ' ' + args777 + (cmd.description()759 ? ' ' + cmd.description()760 : '');778 ? '\n ' + cmd.description()779 : '')780 + '\n';781 }).join('\n').replace(/^/gm, ' ')782 , ''783 ].join('\n');784};
7 unmodified lines
792793Command.prototype.helpInformation = function(){794 return [795 ''776 , ' Usage: ' + this._name + ' ' + this.usage()796 , ' Usage: ' + this._name797 + (this._alias798 ? '|' + this._alias799 : '')800 + ' ' + this.usage()801 , '' + this.commandHelp()802 , ' Options:'803 , ''804 , '' + this.optionHelp().replace(/^/gm, ' ')
72 unmodified lines