Comparing version
@@ -84,10 +84,10 @@ /** | ||
if(arg[1].substr(0,3) == 'no-') { | ||
options[Commands.toCamelCase(arg[1].substring(3))] = false; | ||
Commands.optionsAppender(options, arg[1].substring(3), false); | ||
} | ||
else { | ||
options[Commands.toCamelCase(arg[1])] = true; | ||
Commands.optionsAppender(options, arg[1], true); | ||
} | ||
} | ||
else { | ||
options[Commands.toCamelCase(option[0])] = option.length > 1 ? option[1] : null; | ||
Commands.optionsAppender(options, option[0], option.length > 1 ? option[1] : null); | ||
} | ||
@@ -122,10 +122,10 @@ } | ||
if(arg[1].substr(0,3) == 'no-') { | ||
options[Commands.toCamelCase(arg[1].substring(3))] = false; | ||
Commands.optionsAppender(options, arg[1].substring(3), false); | ||
} | ||
else { | ||
options[Commands.toCamelCase(arg[1])] = true; | ||
Commands.optionsAppender(options, arg[1], true); | ||
} | ||
} | ||
else if(argv[i].charAt(0) == '-') { | ||
options[Commands.toCamelCase(argv[i].substring(1))] = argv[++i]; | ||
Commands.optionsAppender(options, argv[i].substring(1), argv[++i]); | ||
} | ||
@@ -138,2 +138,23 @@ } | ||
/** | ||
* Appends the named key value pair into the options object. When the key already exists, the value is appended | ||
* to the existing value as an array. | ||
* | ||
* @param {Object} options | ||
* @param {String} key | ||
* @param {String} value | ||
*/ | ||
Commands.optionsAppender = function(options, key, value) { | ||
var camelCaseKey = Commands.toCamelCase(key); | ||
if(options[camelCaseKey] === undefined) { | ||
options[camelCaseKey] = value; | ||
} | ||
else if(Array.isArray(options[camelCaseKey])) { | ||
options[camelCaseKey].push(value); | ||
} | ||
else { | ||
options[camelCaseKey] = [options[camelCaseKey], value]; | ||
} | ||
}; | ||
/** | ||
* Creates a new string that has been converted to camel case where any non letter is treated as a word break. | ||
@@ -140,0 +161,0 @@ * @return {String} |
{ | ||
"name": "commands", | ||
"description": "Command line arguments reader", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"author": "Steve King <steve@mydev.co>", | ||
@@ -6,0 +6,0 @@ "contributors": [ { "name": "Steve King", "email": "steve@mydev.co" } ], |
28360
266.5%12
140%152
12.59%