Permalink
Browse files

lots of little style nits

  • Loading branch information...
1 parent 6e035db commit e0f32186a309adf986865458b64cae9a94d053cd @fat fat committed Apr 7, 2012
View
@@ -32,7 +32,7 @@
* from this code.
*/
-var UnknownMainError = require('./errors').UnknownMainError
+var UnknownMainError = require('./errors').UnknownMainError
, UnknownOptionError = require('./errors').UnknownOptionError
// the default array option to collect arguments for ('packages'), so all non
@@ -47,19 +47,22 @@ var UnknownMainError = require('./errors').UnknownMainError
, options = (function () {
var arr = []
, add = function (name, short, type, altMain) {
+ var o
+
if (typeof short != 'string') {
altMain = type
- type = short
- short = null
+ type = short
+ short = null
}
- var o = {
- name: name
- , short: short
- , type: type
- , altMain: altMain
+
+ o = {
+ name : name
+ , short : short
+ , type : type
+ , altMain : altMain
}
- if (short === '' && type === Array)
- defaultArray = name
+
+ if (short === '' && type === Array) defaultArray = name
arr.push(o)
}
@@ -82,31 +85,36 @@ var UnknownMainError = require('./errors').UnknownMainError
// allowable first-arguments that resolve to our main-X.js modules.
, mains = {
- 'help': 'help'
- , 'build': 'build'
- , 'add': 'add'
- , 'set': 'add'
- , 'refresh': 'add'
- , 'remove': 'remove'
- , 'rm': 'remove'
- , 'info': 'info'
- , 'ls': 'info'
- , 'list': 'info'
- , 'search': 'search'
- , 'compile': 'compile'
- , 'version': 'version'
+ 'help' : 'help'
+ , 'build' : 'build'
+ , 'add' : 'add'
+ , 'set' : 'add'
+ , 'refresh' : 'add'
+ , 'remove' : 'remove'
+ , 'rm' : 'remove'
+ , 'info' : 'info'
+ , 'ls' : 'info'
+ , 'list' : 'info'
+ , 'search' : 'search'
+ , 'compile' : 'compile'
+ , 'version' : 'version'
}
, findOption = function (s) {
- var i, option, match = s.match(/^(--?)(\w+)$/)
- if (!match)
- return
+ var i
+ , option
+ , match = s.match(/^(--?)(\w+)$/)
+
+ if (!match) return
+
for (i = 0; i < options.length; i++) {
- option = options[i]
- if (
- (match[1] === '--' && match[2] === option.name)
- || (match[1] === '-' && option.short && match[2] === option.short))
- return option
+ var hasOption
+
+ option = options[i]
+ hasOption = (match[1] === '--' && match[2] === option.name)
+ || (match[1] === '-' && option.short && match[2] === option.short)
+
+ if (hasOption) return option
}
throw new UnknownOptionError('Unknown option "' + s + '"')
}
@@ -117,16 +125,16 @@ var UnknownMainError = require('./errors').UnknownMainError
, toContextString = function (options) {
var str = options.main
, p
- if (options.packages.length)
- str += ' ' + options.packages.join(' ')
+
+ if (options.packages.length) str += ' ' + options.packages.join(' ')
+
for (p in options) {
- if (p === 'packages' || p === 'main')
- continue
+ if (p === 'packages' || p === 'main') continue
+
str += ' --' + p
- if (Array.isArray(options[p]))
- str += ' ' + options[p].join(' ')
- else if (typeof options[p] !== 'boolean')
- str += ' ' + options[p]
+
+ if (Array.isArray(options[p])) str += ' ' + options[p].join(' ')
+ else if (typeof options[p] !== 'boolean') str += ' ' + options[p]
}
return str
}
@@ -149,26 +157,28 @@ var UnknownMainError = require('./errors').UnknownMainError
o = findOption(arg)
if (o) {
currentArray = defaultArray
+
if (o.type === Boolean) {
options[o.name] = true
- if (o.altMain && !options.main)
- options.main = o.name
- } else if ((o.type === String || o.type === Number) && args.length)
- options[o.name] = o.type(args.shift()) // converstion through type constructor
- else if (o.type === Array)
+ if (o.altMain && !options.main) options.main = o.name
+ } else if ((o.type === String || o.type === Number) && args.length) {
+ // converstion through type constructor
+ options[o.name] = o.type(args.shift())
+ } else if (o.type === Array) {
setCurrentArray(o.name)
+ }
+
} else if (!options.main) {
options.main = arg
- } else
+ } else {
options[currentArray].push(arg)
+ }
}
- if (!options.main)
- throw new UnknownMainError('No main command supplied')
- if (!mains[options.main])
- throw new UnknownMainError('Unknown main command "' + options.main + '"')
- else
- options.main = mains[options.main]
+ if (!options.main) throw new UnknownMainError('No main command supplied')
+ if (!mains[options.main]) throw new UnknownMainError('Unknown main command "' + options.main + '"')
+ options.main = mains[options.main]
+
return options
}
@@ -178,12 +188,8 @@ var UnknownMainError = require('./errors').UnknownMainError
}
module.exports = {
- parse: function (argv) { // with 2 additional args 'node script.js'
- return parse(argv, 2)
- }
- , parseClean: function (argv) { // without
- return parse(argv, 0)
- }
- , toContextString: toContextString
- , extend: extend
+ parse : function (argv) { return parse(argv, 2) } // with 2 additional args 'node script.js'
+ , parseClean : function (argv) { return parse(argv, 0) } // without
+ , extend : extend
+ , toContextString : toContextString
}
View
@@ -63,22 +63,22 @@ EnderError.prototype = new Error()
// full err list https://github.com/joyent/libuv/blob/master/include/uv.h
function getFilesystemErrorMessage (err) {
switch (err.errno) {
- case 3 : return 'permission denied'
- case 9 : return 'bad file descriptor'
- case 10: return 'resource/file busy or locked'
- case 20: return 'too many files open'
- case 24: return 'file table overflow'
- case 25: return 'no buffer space available'
- case 26: return 'not enough memory'
- case 27: return 'not a directory'
- case 28: return 'illegal operation on a directory'
- case 34: return 'no such file or directory'
- case 47: return 'file already exists'
- case 49: return 'name too long'
- case 50: return 'operation not permitted'
- case 51: return 'too many symbolic links'
- case 53: return 'directory not empty'
- case 54: return 'no space left on device'
+ case 3 : return 'permission denied'
+ case 9 : return 'bad file descriptor'
+ case 10 : return 'resource/file busy or locked'
+ case 20 : return 'too many files open'
+ case 24 : return 'file table overflow'
+ case 25 : return 'no buffer space available'
+ case 26 : return 'not enough memory'
+ case 27 : return 'not a directory'
+ case 28 : return 'illegal operation on a directory'
+ case 34 : return 'no such file or directory'
+ case 47 : return 'file already exists'
+ case 49 : return 'name too long'
+ case 50 : return 'operation not permitted'
+ case 51 : return 'too many symbolic links'
+ case 53 : return 'directory not empty'
+ case 54 : return 'no space left on device'
}
return err.message
}
@@ -92,10 +92,10 @@ function createError (name) {
var err = function (message, cause) {
init.call(this, name, message, cause)
if (name == 'FilesystemError') {
- this.message = createFilesystemErrorMessage(this.cause)
this.code = this.cause.code
this.path = this.cause.path
this.errno = this.cause.errno
+ this.message = createFilesystemErrorMessage(this.cause)
}
Error.call(this)
Error.captureStackTrace(this, arguments.callee)
View
@@ -32,18 +32,16 @@
* module which does all the hard work.
*/
-var util = require('./util')
- , mainBuild = require('./main-build')
+var util = require('./util')
+ , argsParse = require('./args-parse')
+ , mainBuild = require('./main-build')
, mainInfoUtil = require('./main-info-util')
- , argsParse = require('./args-parse')
, exec = function (options, out, callback) {
var filename = util.getInputFilenameFromOptions(options)
- ;delete options.use // don't want --use showing up in the 'Build:' context string
+ ; delete options.use // don't want --use showing up in the 'Build:' context string
mainInfoUtil.parseContext(filename, function (err, context) {
- if (err)
- return callback(err) // err wrapped in SourceBuild.parseContext()
-
+ if (err) return callback(err) // err wrapped in SourceBuild.parseContext()
// merge commandline args with the build command in ender.js
options = argsParse.extend(context.options, options)
mainBuild.exec(options, out, callback)
Oops, something went wrong.

0 comments on commit e0f3218

Please sign in to comment.