Skip to content

Commit

Permalink
Merge pull request #272 from zhiyelee/lint
Browse files Browse the repository at this point in the history
Ensure all '('' have a space before '{'
  • Loading branch information
thethomaseffect committed Oct 8, 2014
2 parents ffe9ff3 + ae24232 commit 0ecb81c
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Option(flags, description) {
* @api private
*/

Option.prototype.name = function(){
Option.prototype.name = function() {
return this.long
.replace('--', '')
.replace('no-', '');
Expand All @@ -67,7 +67,7 @@ Option.prototype.name = function(){
* @api private
*/

Option.prototype.is = function(arg){
Option.prototype.is = function(arg) {
return arg == this.short || arg == this.long;
};

Expand Down Expand Up @@ -115,21 +115,21 @@ Command.prototype.__proto__ = EventEmitter.prototype;
* program
* .command('setup')
* .description('run remote setup commands')
* .action(function(){
* .action(function() {
* console.log('setup');
* });
*
* program
* .command('exec <cmd>')
* .description('run the given remote command')
* .action(function(cmd){
* .action(function(cmd) {
* console.log('exec "%s"', cmd);
* });
*
* program
* .command('*')
* .description('deploy the given env')
* .action(function(env){
* .action(function(env) {
* console.log('deploying "%s"', env);
* });
*
Expand Down Expand Up @@ -175,10 +175,10 @@ Command.prototype.addImplicitHelpCommand = function() {
* @api public
*/

Command.prototype.parseExpectedArgs = function(args){
Command.prototype.parseExpectedArgs = function(args) {
if (!args.length) return;
var self = this;
args.forEach(function(arg){
args.forEach(function(arg) {
switch (arg[0]) {
case '<':
self._args.push({ required: true, name: arg.slice(1, -1) });
Expand All @@ -199,7 +199,7 @@ Command.prototype.parseExpectedArgs = function(args){
* program
* .command('help')
* .description('display verbose help')
* .action(function(){
* .action(function() {
* // output help here
* });
*
Expand All @@ -208,9 +208,9 @@ Command.prototype.parseExpectedArgs = function(args){
* @api public
*/

Command.prototype.action = function(fn){
Command.prototype.action = function(fn) {
var self = this;
var listener = function(args, unknown){
var listener = function(args, unknown) {
// Parse any so-far unknown options
args = args || [];
unknown = unknown || [];
Expand All @@ -230,7 +230,7 @@ Command.prototype.action = function(fn){
// Leftover arguments need to be pushed back. Fixes issue #56
if (parsed.args.length) args = parsed.args.concat(args);

self._args.forEach(function(arg, i){
self._args.forEach(function(arg, i) {
if (arg.required && null == args[i]) {
self.missingArgument(arg.name);
}
Expand Down Expand Up @@ -301,7 +301,7 @@ Command.prototype.action = function(fn){
* @api public
*/

Command.prototype.option = function(flags, description, fn, defaultValue){
Command.prototype.option = function(flags, description, fn, defaultValue) {
var self = this
, option = new Option(flags, description)
, oname = option.name()
Expand All @@ -326,7 +326,7 @@ Command.prototype.option = function(flags, description, fn, defaultValue){

// when it's passed assign the value
// and conditionally invoke the callback
this.on(oname, function(val){
this.on(oname, function(val) {
// coercion
if (null !== val && fn) val = fn(val, undefined === self[name]
? defaultValue
Expand Down Expand Up @@ -359,7 +359,7 @@ Command.prototype.option = function(flags, description, fn, defaultValue){
* @api public
*/

Command.prototype.parse = function(argv){
Command.prototype.parse = function(argv) {
// implicit help
if (this.executables) this.addImplicitHelpCommand();

Expand Down Expand Up @@ -416,7 +416,7 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
args = args.slice(1);
args.unshift(local);
var proc = spawn('node', args, { stdio: 'inherit', customFds: [0, 1, 2] });
proc.on('error', function(err){
proc.on('error', function(err) {
if (err.code == "ENOENT") {
console.error('\n %s(1) does not exist, try --help\n', bin);
} else if (err.code == "EACCES") {
Expand All @@ -437,7 +437,7 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
* @api private
*/

Command.prototype.normalize = function(args){
Command.prototype.normalize = function(args) {
var ret = []
, arg
, lastOpt
Expand All @@ -451,12 +451,12 @@ Command.prototype.normalize = function(args){

if (arg === '--') {
// Honor option terminator
ret = ret.concat(args.slice(i));
break;
ret = ret.concat(args.slice(i));
break;
} else if (lastOpt && lastOpt.required) {
ret.push(arg);
ret.push(arg);
} else if (arg.length > 1 && '-' == arg[0] && '-' != arg[1]) {
arg.slice(1).split('').forEach(function(c){
arg.slice(1).split('').forEach(function(c) {
ret.push('-' + c);
});
} else if (/^--/.test(arg) && ~(index = arg.indexOf('='))) {
Expand All @@ -481,7 +481,7 @@ Command.prototype.normalize = function(args){
* @api private
*/

Command.prototype.parseArgs = function(args, unknown){
Command.prototype.parseArgs = function(args, unknown) {
var name;

if (args.length) {
Expand Down Expand Up @@ -512,7 +512,7 @@ Command.prototype.parseArgs = function(args, unknown){
* @api private
*/

Command.prototype.optionFor = function(arg){
Command.prototype.optionFor = function(arg) {
for (var i = 0, len = this.options.length; i < len; ++i) {
if (this.options[i].is(arg)) {
return this.options[i];
Expand All @@ -529,7 +529,7 @@ Command.prototype.optionFor = function(arg){
* @api public
*/

Command.prototype.parseOptions = function(argv){
Command.prototype.parseOptions = function(argv) {
var args = []
, len = argv.length
, literal
Expand Down Expand Up @@ -623,7 +623,7 @@ Command.prototype.opts = function() {
* @api private
*/

Command.prototype.missingArgument = function(name){
Command.prototype.missingArgument = function(name) {
console.error();
console.error(" error: missing required argument `%s'", name);
console.error();
Expand All @@ -638,7 +638,7 @@ Command.prototype.missingArgument = function(name){
* @api private
*/

Command.prototype.optionMissingArgument = function(option, flag){
Command.prototype.optionMissingArgument = function(option, flag) {
console.error();
if (flag) {
console.error(" error: option `%s' argument missing, got `%s'", option.flags, flag);
Expand All @@ -656,7 +656,7 @@ Command.prototype.optionMissingArgument = function(option, flag){
* @api private
*/

Command.prototype.unknownOption = function(flag){
Command.prototype.unknownOption = function(flag) {
console.error();
console.error(" error: unknown option `%s'", flag);
console.error();
Expand All @@ -676,12 +676,12 @@ Command.prototype.unknownOption = function(flag){
* @api public
*/

Command.prototype.version = function(str, flags){
Command.prototype.version = function(str, flags) {
if (0 == arguments.length) return this._version;
this._version = str;
flags = flags || '-V, --version';
this.option(flags, 'output the version number');
this.on('version', function(){
this.on('version', function() {
process.stdout.write(str + '\n');
process.exit(0);
});
Expand All @@ -696,7 +696,7 @@ Command.prototype.version = function(str, flags){
* @api public
*/

Command.prototype.description = function(str){
Command.prototype.description = function(str) {
if (0 == arguments.length) return this._description;
this._description = str;
return this;
Expand All @@ -710,7 +710,7 @@ Command.prototype.description = function(str){
* @api public
*/

Command.prototype.alias = function(alias){
Command.prototype.alias = function(alias) {
if (0 == arguments.length) return this._alias;
this._alias = alias;
return this;
Expand All @@ -724,8 +724,8 @@ Command.prototype.alias = function(alias){
* @api public
*/

Command.prototype.usage = function(str){
var args = this._args.map(function(arg){
Command.prototype.usage = function(str) {
var args = this._args.map(function(arg) {
return arg.required
? '<' + arg.name + '>'
: '[' + arg.name + ']';
Expand All @@ -749,7 +749,7 @@ Command.prototype.usage = function(str){
* @api public
*/

Command.prototype.name = function(name){
Command.prototype.name = function(name) {
return this._name;
};

Expand All @@ -760,8 +760,8 @@ Command.prototype.name = function(name){
* @api private
*/

Command.prototype.largestOptionLength = function(){
return this.options.reduce(function(max, option){
Command.prototype.largestOptionLength = function() {
return this.options.reduce(function(max, option) {
return Math.max(max, option.flags.length);
}, 0);
};
Expand All @@ -773,12 +773,12 @@ Command.prototype.largestOptionLength = function(){
* @api private
*/

Command.prototype.optionHelp = function(){
Command.prototype.optionHelp = function() {
var width = this.largestOptionLength();

// Prepend the help information
return [pad('-h, --help', width) + ' ' + 'output usage information']
.concat(this.options.map(function(option){
.concat(this.options.map(function(option) {
return pad(option.flags, width) + ' ' + option.description;
}))
.join('\n');
Expand All @@ -791,11 +791,11 @@ Command.prototype.optionHelp = function(){
* @api private
*/

Command.prototype.commandHelp = function(){
Command.prototype.commandHelp = function() {
if (!this.commands.length) return '';

var commands = this.commands.map(function(cmd) {
var args = cmd._args.map(function(arg){
var args = cmd._args.map(function(arg) {
return arg.required
? '<' + arg.name + '>'
: '[' + arg.name + ']';
Expand All @@ -814,15 +814,15 @@ Command.prototype.commandHelp = function(){
];
});

var width = commands.reduce(function(max, command){
var width = commands.reduce(function(max, command) {
return Math.max(max, command[0].length);
}, 0);

return [
''
, ' Commands:'
, ''
, commands.map(function(cmd){
, commands.map(function(cmd) {
return pad(cmd[0], width) + ' ' + cmd[1];
}).join('\n').replace(/^/gm, ' ')
, ''
Expand All @@ -836,7 +836,7 @@ Command.prototype.commandHelp = function(){
* @api private
*/

Command.prototype.helpInformation = function(){
Command.prototype.helpInformation = function() {
return [
''
, ' Usage: ' + this._name
Expand All @@ -859,7 +859,7 @@ Command.prototype.helpInformation = function(){
* @api public
*/

Command.prototype.outputHelp = function(){
Command.prototype.outputHelp = function() {
process.stdout.write(this.helpInformation());
this.emit('--help');
};
Expand All @@ -870,7 +870,7 @@ Command.prototype.outputHelp = function(){
* @api public
*/

Command.prototype.help = function(){
Command.prototype.help = function() {
this.outputHelp();
process.exit();
};
Expand All @@ -884,7 +884,7 @@ Command.prototype.help = function(){
*/

function camelcase(flag) {
return flag.split('-').reduce(function(str, word){
return flag.split('-').reduce(function(str, word) {
return str + word[0].toUpperCase() + word.slice(1);
});
}
Expand Down

0 comments on commit 0ecb81c

Please sign in to comment.