diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/yargs-parser/index.js | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) | |
download | wallet-core-bbff7403fbf46f9ad92240ac213df8d30ef31b64.tar.xz |
update packages
Diffstat (limited to 'node_modules/yargs-parser/index.js')
-rw-r--r-- | node_modules/yargs-parser/index.js | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/node_modules/yargs-parser/index.js b/node_modules/yargs-parser/index.js index c06d93707..1d3e6b9bc 100644 --- a/node_modules/yargs-parser/index.js +++ b/node_modules/yargs-parser/index.js @@ -19,7 +19,8 @@ function parse (args, opts) { 'negation-prefix': 'no-', 'duplicate-arguments-array': true, 'flatten-duplicate-arrays': true, - 'populate--': false + 'populate--': false, + 'combine-arrays': false }, opts.configuration) var defaults = opts.default || {} var configObjects = opts.configObjects || [] @@ -425,7 +426,9 @@ function parse (args, opts) { function maybeCoerceNumber (key, value) { if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.coercions)) { - const shouldCoerceNumber = isNumber(value) && configuration['parse-numbers'] && (Number.isSafeInteger(parseInt(value))) + const shouldCoerceNumber = isNumber(value) && configuration['parse-numbers'] && ( + Number.isSafeInteger(Math.floor(value)) + ) if (shouldCoerceNumber || (!isUndefined(value) && checkAllAliases(key, flags.numbers))) value = Number(value) } return value @@ -479,13 +482,13 @@ function parse (args, opts) { // if the value is an inner object and we have dot-notation // enabled, treat inner objects in config the same as // heavily nested dot notations (foo.bar.apple). - if (typeof value === 'object' && !Array.isArray(value) && configuration['dot-notation']) { + if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) { // if the value is an object but not an array, check nested object setConfigObject(value, fullKey) } else { // setting arguments via CLI takes precedence over // values within the config file. - if (!hasKey(argv, fullKey.split('.')) || (flags.defaulted[fullKey])) { + if (!hasKey(argv, fullKey.split('.')) || (flags.defaulted[fullKey]) || (flags.arrays[fullKey] && configuration['combine-arrays'])) { setArg(fullKey, value) } } @@ -523,13 +526,19 @@ function parse (args, opts) { function applyCoercions (argv) { var coerce + var applied = {} Object.keys(argv).forEach(function (key) { - coerce = checkAllAliases(key, flags.coercions) - if (typeof coerce === 'function') { - try { - argv[key] = coerce(argv[key]) - } catch (err) { - error = err + if (!applied.hasOwnProperty(key)) { // If we haven't already coerced this option via one of its aliases + coerce = checkAllAliases(key, flags.coercions) + if (typeof coerce === 'function') { + try { + var value = coerce(argv[key]) + ;([].concat(flags.aliases[key] || [], key)).forEach(ali => { + applied[ali] = argv[ali] = value + }) + } catch (err) { + error = err + } } } }) @@ -568,9 +577,24 @@ function parse (args, opts) { if (!configuration['dot-notation']) keys = [keys.join('.')] - keys.slice(0, -1).forEach(function (key) { - if (o[key] === undefined) o[key] = {} - o = o[key] + keys.slice(0, -1).forEach(function (key, index) { + if (typeof o === 'object' && o[key] === undefined) { + o[key] = {} + } + + if (typeof o[key] !== 'object' || Array.isArray(o[key])) { + // ensure that o[key] is an array, and that the last item is an empty object. + if (Array.isArray(o[key])) { + o[key].push({}) + } else { + o[key] = [o[key], {}] + } + + // we want to update the empty object at the end of the o[key] array, so set o to that object + o = o[key][o[key].length - 1] + } else { + o = o[key] + } }) var key = keys[keys.length - 1] @@ -612,10 +636,10 @@ function parse (args, opts) { flags.aliases[key].concat(key).forEach(function (x) { if (/-/.test(x) && configuration['camel-case-expansion']) { var c = camelCase(x) - if (flags.aliases[key].indexOf(c) === -1) { + if (c !== key && flags.aliases[key].indexOf(c) === -1) { flags.aliases[key].push(c) + newAliases[c] = true } - newAliases[c] = true } }) flags.aliases[key].forEach(function (x) { |