Skip to content
Myr

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

1 file+45 added−45 removed

modified:index.js+45 added-45 removed
51 unmodified lines
52 * @return {String}53 * @api private54 */5556Option.prototype.name = function(){56Option.prototype.name = function() {57 return this.long58 .replace('--', '')59 .replace('no-', '');60};
5 unmodified lines
66 * @return {Boolean}67 * @api private68 */6970Option.prototype.is = function(arg){70Option.prototype.is = function(arg) {71 return arg == this.short || arg == this.long;72};7374/**
39 unmodified lines
114 *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 lines
174 * @return {Command} for chaining175 * @api public176 */177178Command.prototype.parseExpectedArgs = function(args){178Command.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 lines
198 *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 */210211Command.prototype.action = function(fn){211Command.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 lines
229230 // Leftover arguments need to be pushed back. Fixes issue #56231 if (parsed.args.length) args = parsed.args.concat(args);232233 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 lines
300 * @return {Command} for chaining301 * @api public302 */303304Command.prototype.option = function(flags, description, fn, defaultValue){304Command.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 lines
325 this.options.push(option);326327 // 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 lines
358 * @return {Command} for chaining359 * @api public360 */361362Command.prototype.parse = function(argv){362Command.prototype.parse = function(argv) {363 // implicit help364 if (this.executables) this.addImplicitHelpCommand();365366 // store raw args
48 unmodified lines
415 // 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 lines
436 * @return {Array}437 * @api private438 */439440Command.prototype.normalize = function(args){440Command.prototype.normalize = function(args) {441 var ret = []442 , arg443 , lastOpt444 , index;
5 unmodified lines
450 }451452 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 lines
480 * @return {Command} for chaining481 * @api private482 */483484Command.prototype.parseArgs = function(args, unknown){484Command.prototype.parseArgs = function(args, unknown) {485 var name;486487 if (args.length) {488 name = args[0];
22 unmodified lines
511 * @return {Option}512 * @api private513 */514515Command.prototype.optionFor = function(arg){515Command.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 lines
528 * @return {Array}529 * @api public530 */531532Command.prototype.parseOptions = function(argv){532Command.prototype.parseOptions = function(argv) {533 var args = []534 , len = argv.length535 , literal536 , option
85 unmodified lines
622 * @param {String} name623 * @api private624 */625626Command.prototype.missingArgument = function(name){626Command.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 lines
637 * @param {String} flag638 * @api private639 */640641Command.prototype.optionMissingArgument = function(option, flag){641Command.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 lines
655 * @param {String} flag656 * @api private657 */658659Command.prototype.unknownOption = function(flag){659Command.prototype.unknownOption = function(flag) {660 console.error();661 console.error(" error: unknown option `%s'", flag);662 console.error();663 process.exit(1);
11 unmodified lines
675 * @return {Command} for chaining676 * @api public677 */678679Command.prototype.version = function(str, flags){679Command.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 lines
695 * @return {String|Command}696 * @api public697 */698699Command.prototype.description = function(str){699Command.prototype.description = function(str) {700 if (0 == arguments.length) return this._description;701 this._description = str;702 return this;703};
5 unmodified lines
709 * @return {String|Command}710 * @api public711 */712713Command.prototype.alias = function(alias){713Command.prototype.alias = function(alias) {714 if (0 == arguments.length) return this._alias;715 this._alias = alias;716 return this;717};
5 unmodified lines
723 * @return {String|Command}724 * @api public725 */726727Command.prototype.usage = function(str){728 var args = this._args.map(function(arg){727Command.prototype.usage = function(str) {728 var args = this._args.map(function(arg) {729 return arg.required730 ? '<' + arg.name + '>'731 : '[' + arg.name + ']';732 });
15 unmodified lines
748 * @return {String|Command}749 * @api public750 */751752Command.prototype.name = function(name){752Command.prototype.name = function(name) {753 return this._name;754};755756/**
2 unmodified lines
759 * @return {Number}760 * @api private761 */762763Command.prototype.largestOptionLength = function(){764 return this.options.reduce(function(max, option){763Command.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 lines
772 * @return {String}773 * @api private774 */775776Command.prototype.optionHelp = function(){776Command.prototype.optionHelp = function() {777 var width = this.largestOptionLength();778779 // 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 lines
790 * @return {String}791 * @api private792 */793794Command.prototype.commandHelp = function(){794Command.prototype.commandHelp = function() {795 if (!this.commands.length) return '';796797 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 lines
813 , cmd.description()814 ];815 });816817 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);820821 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 lines
835 * @return {String}836 * @api private837 */838839Command.prototype.helpInformation = function(){839Command.prototype.helpInformation = function() {840 return [841 ''842 , ' Usage: ' + this._name843 + (this._alias
14 unmodified lines
858 *859 * @api public860 */861862Command.prototype.outputHelp = function(){862Command.prototype.outputHelp = function() {863 process.stdout.write(this.helpInformation());864 this.emit('--help');865};866
2 unmodified lines
869 *870 * @api public871 */872873Command.prototype.help = function(){873Command.prototype.help = function() {874 this.outputHelp();875 process.exit();876};877
5 unmodified lines
883 * @api private884 */885886function 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