lint `){` ==> `) {`
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by zhiyelee · committed by zhiyelee · parent ffe9ff3 · Browse files · 1 file·+45 added−45 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+45 added−45 removed
- other:+45 added−45 removed
Provenance
- Commit
ae24232- Tree
1ef99a0- Author
zhiyelee <zhiyelee@gmail.com>- Committer
zhiyelee <zhiyelee@gmail.com>- Parent
ffe9ff3
1 file changed+45 added−45 removed
modified:index.js+45 added-45 removed
51 unmodified lines52 * @return {String}53 * @api private54 */55 56-Option.prototype.name = function(){56+Option.prototype.name = function() {57 return this.long58 .replace('--', '')59 .replace('no-', '');60 };5 unmodified lines66 * @return {Boolean}67 * @api private68 */69 70-Option.prototype.is = function(arg){70+Option.prototype.is = function(arg) {71 return arg == this.short || arg == this.long;72 };73 74 /**39 unmodified lines114 *115 * program116 * .command('setup')117 * .description('run remote setup commands')118- * .action(function(){118+ * .action(function() {119 * console.log('setup');120 * });121 *122 * program123 * .command('exec <cmd>')124 * .description('run the given remote command')125- * .action(function(cmd){125+ * .action(function(cmd) {126 * console.log('exec "%s"', cmd);127 * });128 *129 * program130 * .command('*')131 * .description('deploy the given env')132- * .action(function(env){132+ * .action(function(env) {133 * console.log('deploying "%s"', env);134 * });135 *136 * program.parse(process.argv);37 unmodified lines174 * @return {Command} for chaining175 * @api public176 */177 178-Command.prototype.parseExpectedArgs = function(args){178+Command.prototype.parseExpectedArgs = function(args) {179 if (!args.length) return;180 var self = this;181- args.forEach(function(arg){181+ args.forEach(function(arg) {182 switch (arg[0]) {183 case '<':184 self._args.push({ required: true, name: arg.slice(1, -1) });185 break;12 unmodified lines198 *199 * program200 * .command('help')201 * .description('display verbose help')202- * .action(function(){202+ * .action(function() {203 * // output help here204 * });205 *206 * @param {Function} fn207 * @return {Command} for chaining208 * @api public209 */210 211-Command.prototype.action = function(fn){211+Command.prototype.action = function(fn) {212 var self = this;213- var listener = function(args, unknown){213+ var listener = function(args, unknown) {214 // Parse any so-far unknown options215 args = args || [];216 unknown = unknown || [];217 11 unmodified lines229 230 // Leftover arguments need to be pushed back. Fixes issue #56231 if (parsed.args.length) args = parsed.args.concat(args);232 233- self._args.forEach(function(arg, i){233+ self._args.forEach(function(arg, i) {234 if (arg.required && null == args[i]) {235 self.missingArgument(arg.name);236 }237 });62 unmodified lines300 * @return {Command} for chaining301 * @api public302 */303 304-Command.prototype.option = function(flags, description, fn, defaultValue){304+Command.prototype.option = function(flags, description, fn, defaultValue) {305 var self = this306 , option = new Option(flags, description)307 , oname = option.name()308 , name = camelcase(oname);16 unmodified lines325 this.options.push(option);326 327 // when it's passed assign the value328 // and conditionally invoke the callback329- this.on(oname, function(val){329+ this.on(oname, function(val) {330 // coercion331 if (null !== val && fn) val = fn(val, undefined === self[name]332 ? defaultValue333 : self[name]);24 unmodified lines358 * @return {Command} for chaining359 * @api public360 */361 362-Command.prototype.parse = function(argv){362+Command.prototype.parse = function(argv) {363 // implicit help364 if (this.executables) this.addImplicitHelpCommand();365 366 // store raw args48 unmodified lines415 // run it416 args = args.slice(1);417 args.unshift(local);418 var proc = spawn('node', args, { stdio: 'inherit', customFds: [0, 1, 2] });419- proc.on('error', function(err){419+ proc.on('error', function(err) {420 if (err.code == "ENOENT") {421 console.error('\n %s(1) does not exist, try --help\n', bin);422 } else if (err.code == "EACCES") {423 console.error('\n %s(1) not executable. try chmod or run with root\n', bin);12 unmodified lines436 * @return {Array}437 * @api private438 */439 440-Command.prototype.normalize = function(args){440+Command.prototype.normalize = function(args) {441 var ret = []442 , arg443 , lastOpt444 , index;5 unmodified lines450 }451 452 if (arg === '--') {453 // Honor option terminator454- ret = ret.concat(args.slice(i));455- break;454+ ret = ret.concat(args.slice(i));455+ break;456 } else if (lastOpt && lastOpt.required) {457- ret.push(arg);457+ ret.push(arg);458 } else if (arg.length > 1 && '-' == arg[0] && '-' != arg[1]) {459- arg.slice(1).split('').forEach(function(c){459+ arg.slice(1).split('').forEach(function(c) {460 ret.push('-' + c);461 });462 } else if (/^--/.test(arg) && ~(index = arg.indexOf('='))) {463 ret.push(arg.slice(0, index), arg.slice(index + 1));16 unmodified lines480 * @return {Command} for chaining481 * @api private482 */483 484-Command.prototype.parseArgs = function(args, unknown){484+Command.prototype.parseArgs = function(args, unknown) {485 var name;486 487 if (args.length) {488 name = args[0];22 unmodified lines511 * @return {Option}512 * @api private513 */514 515-Command.prototype.optionFor = function(arg){515+Command.prototype.optionFor = function(arg) {516 for (var i = 0, len = this.options.length; i < len; ++i) {517 if (this.options[i].is(arg)) {518 return this.options[i];519 }8 unmodified lines528 * @return {Array}529 * @api public530 */531 532-Command.prototype.parseOptions = function(argv){532+Command.prototype.parseOptions = function(argv) {533 var args = []534 , len = argv.length535 , literal536 , option85 unmodified lines622 * @param {String} name623 * @api private624 */625 626-Command.prototype.missingArgument = function(name){626+Command.prototype.missingArgument = function(name) {627 console.error();628 console.error(" error: missing required argument `%s'", name);629 console.error();630 process.exit(1);6 unmodified lines637 * @param {String} flag638 * @api private639 */640 641-Command.prototype.optionMissingArgument = function(option, flag){641+Command.prototype.optionMissingArgument = function(option, flag) {642 console.error();643 if (flag) {644 console.error(" error: option `%s' argument missing, got `%s'", option.flags, flag);645 } else {9 unmodified lines655 * @param {String} flag656 * @api private657 */658 659-Command.prototype.unknownOption = function(flag){659+Command.prototype.unknownOption = function(flag) {660 console.error();661 console.error(" error: unknown option `%s'", flag);662 console.error();663 process.exit(1);11 unmodified lines675 * @return {Command} for chaining676 * @api public677 */678 679-Command.prototype.version = function(str, flags){679+Command.prototype.version = function(str, flags) {680 if (0 == arguments.length) return this._version;681 this._version = str;682 flags = flags || '-V, --version';683 this.option(flags, 'output the version number');684- this.on('version', function(){684+ this.on('version', function() {685 process.stdout.write(str + '\n');686 process.exit(0);687 });688 return this;6 unmodified lines695 * @return {String|Command}696 * @api public697 */698 699-Command.prototype.description = function(str){699+Command.prototype.description = function(str) {700 if (0 == arguments.length) return this._description;701 this._description = str;702 return this;703 };5 unmodified lines709 * @return {String|Command}710 * @api public711 */712 713-Command.prototype.alias = function(alias){713+Command.prototype.alias = function(alias) {714 if (0 == arguments.length) return this._alias;715 this._alias = alias;716 return this;717 };5 unmodified lines723 * @return {String|Command}724 * @api public725 */726 727-Command.prototype.usage = function(str){728- var args = this._args.map(function(arg){727+Command.prototype.usage = function(str) {728+ var args = this._args.map(function(arg) {729 return arg.required730 ? '<' + arg.name + '>'731 : '[' + arg.name + ']';732 });15 unmodified lines748 * @return {String|Command}749 * @api public750 */751 752-Command.prototype.name = function(name){752+Command.prototype.name = function(name) {753 return this._name;754 };755 756 /**2 unmodified lines759 * @return {Number}760 * @api private761 */762 763-Command.prototype.largestOptionLength = function(){764- return this.options.reduce(function(max, option){763+Command.prototype.largestOptionLength = function() {764+ return this.options.reduce(function(max, option) {765 return Math.max(max, option.flags.length);766 }, 0);767 };768 3 unmodified lines772 * @return {String}773 * @api private774 */775 776-Command.prototype.optionHelp = function(){776+Command.prototype.optionHelp = function() {777 var width = this.largestOptionLength();778 779 // Prepend the help information780 return [pad('-h, --help', width) + ' ' + 'output usage information']781- .concat(this.options.map(function(option){781+ .concat(this.options.map(function(option) {782 return pad(option.flags, width) + ' ' + option.description;783 }))784 .join('\n');785 };4 unmodified lines790 * @return {String}791 * @api private792 */793 794-Command.prototype.commandHelp = function(){794+Command.prototype.commandHelp = function() {795 if (!this.commands.length) return '';796 797 var commands = this.commands.map(function(cmd) {798- var args = cmd._args.map(function(arg){798+ var args = cmd._args.map(function(arg) {799 return arg.required800 ? '<' + arg.name + '>'801 : '[' + arg.name + ']';802 }).join(' ');10 unmodified lines813 , cmd.description()814 ];815 });816 817- var width = commands.reduce(function(max, command){817+ var width = commands.reduce(function(max, command) {818 return Math.max(max, command[0].length);819 }, 0);820 821 return [822 ''823 , ' Commands:'824 , ''825- , commands.map(function(cmd){825+ , commands.map(function(cmd) {826 return pad(cmd[0], width) + ' ' + cmd[1];827 }).join('\n').replace(/^/gm, ' ')828 , ''829 ].join('\n');5 unmodified lines835 * @return {String}836 * @api private837 */838 839-Command.prototype.helpInformation = function(){839+Command.prototype.helpInformation = function() {840 return [841 ''842 , ' Usage: ' + this._name843 + (this._alias14 unmodified lines858 *859 * @api public860 */861 862-Command.prototype.outputHelp = function(){862+Command.prototype.outputHelp = function() {863 process.stdout.write(this.helpInformation());864 this.emit('--help');865 };866 2 unmodified lines869 *870 * @api public871 */872 873-Command.prototype.help = function(){873+Command.prototype.help = function() {874 this.outputHelp();875 process.exit();876 };877 5 unmodified lines883 * @api private884 */885 886 function camelcase(flag) {887- return flag.split('-').reduce(function(str, word){887+ return flag.split('-').reduce(function(str, word) {888 return str + word[0].toUpperCase() + word.slice(1);889 });890 }891 31 unmodified lines