Comparing version 0.2.8 to 0.3.0
29
index.js
@@ -314,11 +314,3 @@ var path = require('path'); | ||
if (key in argv && !flags.bools[key]) { | ||
if (!Array.isArray(argv[key])) { | ||
argv[key] = [ argv[key] ]; | ||
} | ||
argv[key].push(value); | ||
} | ||
else { | ||
argv[key] = value; | ||
} | ||
setKey(argv, key.split('.'), value); | ||
@@ -459,1 +451,20 @@ (aliases[key] || []).forEach(function (x) { | ||
}; | ||
function setKey (obj, keys, value) { | ||
var o = obj; | ||
keys.slice(0,-1).forEach(function (key) { | ||
if (o[key] === undefined) o[key] = {}; | ||
o = o[key]; | ||
}); | ||
var key = keys[keys.length - 1]; | ||
if (o[key] === undefined || typeof o[key] === 'boolean') { | ||
o[key] = value; | ||
} | ||
else if (Array.isArray(o[key])) { | ||
o[key].push(value); | ||
} | ||
else { | ||
o[key] = [ o[key], value ]; | ||
} | ||
} |
{ | ||
"name" : "optimist", | ||
"version" : "0.2.8", | ||
"version" : "0.3.0", | ||
"description" : "Light-weight option parsing with an argv hash. No optstrings attached.", | ||
@@ -5,0 +5,0 @@ "main" : "./index.js", |
@@ -305,1 +305,19 @@ var optimist = require('../index'); | ||
}; | ||
exports['nested dotted objects'] = function () { | ||
var argv = optimist([ | ||
'--foo.bar', '3', '--foo.baz', '4', | ||
'--foo.quux.quibble', '5', '--foo.quux.o_O', | ||
'--beep.boop' | ||
]).argv; | ||
assert.deepEqual(argv.foo, { | ||
bar : 3, | ||
baz : 4, | ||
quux : { | ||
quibble : 5, | ||
o_O : true | ||
}, | ||
}); | ||
assert.deepEqual(argv.beep, { boop : true }); | ||
}; |
Sorry, the diff of this file is not supported yet
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
45744
1110
486