Comparing version 0.8.5 to 0.8.6
@@ -5,3 +5,3 @@ // Generated by CoffeeScript 2.6.1 | ||
// Dependencies | ||
var Shell, clone, is_object_literal, merge, set_default, utils, | ||
var Shell, clone, is_object_literal, merge, utils, | ||
indexOf = [].indexOf; | ||
@@ -41,3 +41,3 @@ | ||
parse = function(config, command) { | ||
var _, err, helping, i, key, leftover, len, main, option, params, ref, ref1, ref2, required, shortcut, type, value, values; | ||
var _, err, helping, i, key, leftover, len, main, name, option, params, ref, ref1, ref2, ref3, required, shortcut, type, value, values; | ||
full_params.push(params = {}); | ||
@@ -192,2 +192,13 @@ if (command != null) { | ||
} | ||
ref3 = config.options; | ||
// Apply default values | ||
for (_ in ref3) { | ||
option = ref3[_]; | ||
if (option.default != null) { | ||
if (params[name = option.name] == null) { | ||
params[name] = option.default; | ||
} | ||
} | ||
} | ||
// Return params object associated with this command | ||
return params; | ||
@@ -216,4 +227,2 @@ }; | ||
} | ||
// Enrich params with default values | ||
set_default(appconfig, params); | ||
return params; | ||
@@ -242,5 +251,2 @@ }; | ||
keys = {}; | ||
// In extended mode, the data array will be truncated | ||
// data = merge data unless extended | ||
set_default(appconfig, data); | ||
if (typeof data[appconfig.command] === 'string') { | ||
@@ -259,2 +265,6 @@ // Convert command parameter to a 1 element array if provided as a string | ||
value = ldata[key]; | ||
if (value == null) { | ||
// Apply default value if option missing from params | ||
value = option.default; | ||
} | ||
// Handle required | ||
@@ -359,32 +369,1 @@ required = typeof option.required === 'function' ? !!option.required.call(null, { | ||
}; | ||
// ## Utils | ||
// Given a configuration, apply default values to an object. | ||
set_default = function(config, data, tempdata = null) { | ||
var _, command, name, option, ref; | ||
if (tempdata == null) { | ||
tempdata = merge(data); | ||
} | ||
if (Object.keys(config.commands).length) { | ||
command = tempdata[config.command]; | ||
if (Array.isArray(command)) { | ||
command = tempdata[config.command].shift(); | ||
} | ||
// We are not validating if the command is valid, it may not be set if help option is present | ||
// throw Error "Invalid Command: \"#{command}\"" unless config.commands[command] | ||
if (config.commands[command]) { | ||
data = set_default(config.commands[command], data, tempdata); | ||
} | ||
} | ||
ref = config.options; | ||
for (_ in ref) { | ||
option = ref[_]; | ||
if (option.default != null) { | ||
if (data[name = option.name] == null) { | ||
data[name] = option.default; | ||
} | ||
} | ||
} | ||
return data; | ||
}; |
{ | ||
"name": "shell", | ||
"version": "0.8.5", | ||
"version": "0.8.6", | ||
"author": "David Worms <david@adaltas.com> (https://www.adaltas.com)", | ||
@@ -76,3 +76,3 @@ "coffeelintConfig": { | ||
}, | ||
"gitHead": "2063d9893a477f8a5617dbfc9aca328eb7763bac" | ||
"gitHead": "f54f7430927494236394f6063c2626fbc3c61676" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55384
1438