yargs-parser
Advanced tools
Comparing version 2.4.1 to 3.1.0
@@ -5,2 +5,35 @@ # Change Log | ||
<a name="3.1.0"></a> | ||
# [3.1.0](https://github.com/yargs/yargs-parser/compare/v3.0.0...v3.1.0) (2016-08-09) | ||
### Bug Fixes | ||
* address pkgConf parsing bug outlined in [#37](https://github.com/yargs/yargs-parser/issues/37) ([#45](https://github.com/yargs/yargs-parser/issues/45)) ([be76ee6](https://github.com/yargs/yargs-parser/commit/be76ee6)) | ||
* better parsing of negative values ([#44](https://github.com/yargs/yargs-parser/issues/44)) ([2e43692](https://github.com/yargs/yargs-parser/commit/2e43692)) | ||
* check aliases when guessing defaults for arguments fixes [#41](https://github.com/yargs/yargs-parser/issues/41) ([#43](https://github.com/yargs/yargs-parser/issues/43)) ([f3e4616](https://github.com/yargs/yargs-parser/commit/f3e4616)) | ||
### Features | ||
* added coerce option, for providing specialized argument parsing ([#42](https://github.com/yargs/yargs-parser/issues/42)) ([7b49cd2](https://github.com/yargs/yargs-parser/commit/7b49cd2)) | ||
<a name="3.0.0"></a> | ||
# [3.0.0](https://github.com/yargs/yargs-parser/compare/v2.4.1...v3.0.0) (2016-08-07) | ||
### Bug Fixes | ||
* parsing issue with numeric character in group of options ([#19](https://github.com/yargs/yargs-parser/issues/19)) ([f743236](https://github.com/yargs/yargs-parser/commit/f743236)) | ||
* upgraded lodash.assign ([5d7fdf4](https://github.com/yargs/yargs-parser/commit/5d7fdf4)) | ||
### BREAKING CHANGES | ||
* subtle change to how values are parsed in a group of single-character arguments. | ||
* _first released in 3.1.0, better handling of negative values should be considered a breaking change._ | ||
<a name="2.4.1"></a> | ||
@@ -7,0 +40,0 @@ ## [2.4.1](https://github.com/yargs/yargs-parser/compare/v2.4.0...v2.4.1) (2016-07-16) |
40
index.js
@@ -40,4 +40,6 @@ var assign = require('lodash.assign') | ||
defaulted: {}, | ||
nargs: {} | ||
nargs: {}, | ||
coercions: {} | ||
} | ||
var negative = /^-[0-9]+(\.[0-9]+)?/ | ||
@@ -72,2 +74,6 @@ ;[].concat(opts.array).filter(Boolean).forEach(function (key) { | ||
Object.keys(opts.coerce || {}).forEach(function (k) { | ||
flags.coercions[k] = opts.coerce[k] | ||
}) | ||
if (Array.isArray(opts.config) || typeof opts.config === 'string') { | ||
@@ -155,3 +161,4 @@ ;[].concat(opts.config).filter(Boolean).forEach(function (key) { | ||
if (next !== undefined && !next.match(/^-/) && | ||
if (next !== undefined && (!next.match(/^-/) || | ||
next.match(negative)) && | ||
!checkAllAliases(key, flags.bools) && | ||
@@ -187,3 +194,3 @@ !checkAllAliases(key, flags.counts)) { | ||
} | ||
} else if (arg.match(/^-[^-]+/)) { | ||
} else if (arg.match(/^-[^-]+/) && !arg.match(negative)) { | ||
letters = arg.slice(1, -1).split('') | ||
@@ -220,4 +227,5 @@ broken = false | ||
// current letter is an alphabetic character and next value is a number | ||
if (/[A-Za-z]/.test(letters[j]) && | ||
/-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) { | ||
/^-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) { | ||
setArg(letters[j], next) | ||
@@ -249,3 +257,4 @@ broken = true | ||
if (next !== undefined && !/^(-|--)[^-]/.test(next) && | ||
if (next !== undefined && (!/^(-|--)[^-]/.test(next) || | ||
next.match(negative)) && | ||
!checkAllAliases(key, flags.bools) && | ||
@@ -311,3 +320,3 @@ !checkAllAliases(key, flags.counts)) { | ||
for (var ii = i + 1; ii < args.length; ii++) { | ||
if (/^-/.test(args[ii])) { | ||
if (/^-/.test(args[ii]) && !negative.test(args[ii])) { | ||
if (ii === start) { | ||
@@ -340,3 +349,3 @@ setArg(key, defaultForType('array')) | ||
var value = val | ||
if (!checkAllAliases(key, flags.strings)) { | ||
if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.coercions)) { | ||
if (isNumber(val)) value = Number(val) | ||
@@ -353,3 +362,4 @@ if (!isUndefined(val) && !isNumber(val) && checkAllAliases(key, flags.numbers)) value = NaN | ||
if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) { | ||
value = path.normalize(val) | ||
if (Array.isArray(val)) value = val.map(path.normalize) | ||
else value = path.normalize(val) | ||
} | ||
@@ -523,2 +533,10 @@ | ||
var key = keys[keys.length - 1] | ||
var coerce = checkAllAliases(key, flags.coercions) | ||
if (typeof coerce === 'function') { | ||
try { | ||
value = coerce(value) | ||
} catch (err) { | ||
error = err | ||
} | ||
} | ||
@@ -606,5 +624,5 @@ if (value === increment) { | ||
if (flags.strings && flags.strings[key]) type = 'string' | ||
else if (flags.numbers && flags.numbers[key]) type = 'number' | ||
else if (flags.arrays && flags.arrays[key]) type = 'array' | ||
if (checkAllAliases(key, flags.strings)) type = 'string' | ||
else if (checkAllAliases(key, flags.numbers)) type = 'number' | ||
else if (checkAllAliases(key, flags.arrays)) type = 'array' | ||
@@ -611,0 +629,0 @@ return type |
{ | ||
"name": "yargs-parser", | ||
"version": "2.4.1", | ||
"version": "3.1.0", | ||
"description": "the mighty option parser used by yargs", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"coverage": "nyc report --reporter=text-lcov | coveralls", | ||
"version": "standard-version" | ||
"release": "standard-version" | ||
}, | ||
@@ -31,5 +31,5 @@ "repository": { | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.11.8", | ||
"mocha": "^2.4.5", | ||
"nyc": "^7.0.0", | ||
"coveralls": "^2.11.12", | ||
"mocha": "^3.0.1", | ||
"nyc": "^7.1.0", | ||
"standard": "^7.1.0", | ||
@@ -40,3 +40,3 @@ "standard-version": "^2.1.2" | ||
"camelcase": "^3.0.0", | ||
"lodash.assign": "^4.0.6" | ||
"lodash.assign": "^4.1.0" | ||
}, | ||
@@ -43,0 +43,0 @@ "files": [ |
@@ -57,2 +57,4 @@ # yargs-parser | ||
* `opts.config`: indicate a key that represents a path to a configuration file (this file will be loaded and parsed). | ||
* `opts.coerce`: provide a custom synchronous function that returns a coerced value from the argument provided | ||
(or throws an error), e.g. `{coerce: {foo: function (arg) {return modifiedArg}}}`. | ||
* `opts.count`: indicate a key that should be used as a counter, e.g., `-vvv` = `{v: 3}`. | ||
@@ -59,0 +61,0 @@ * `opts.default`: provide default values for keys: `{default: {x: 33, y: 'hello world!'}}`. |
32471
630
212
Updatedlodash.assign@^4.1.0