yargs-parser
Advanced tools
Comparing version 11.1.1 to 12.0.0
@@ -5,2 +5,23 @@ # Change Log | ||
<a name="12.0.0"></a> | ||
# [12.0.0](https://github.com/yargs/yargs-parser/compare/v11.1.1...v12.0.0) (2019-01-29) | ||
### Bug Fixes | ||
* better handling of quoted strings ([#153](https://github.com/yargs/yargs-parser/issues/153)) ([2fb71b2](https://github.com/yargs/yargs-parser/commit/2fb71b2)) | ||
### Features | ||
* default value is now used if no right-hand value provided for numbers/strings ([#156](https://github.com/yargs/yargs-parser/issues/156)) ([5a7c46a](https://github.com/yargs/yargs-parser/commit/5a7c46a)) | ||
### BREAKING CHANGES | ||
* a flag with no right-hand value no longer populates defaulted options with `undefined`. | ||
* quotes and beginning and endings of strings are not removed during parsing. | ||
<a name="11.1.1"></a> | ||
@@ -7,0 +28,0 @@ ## [11.1.1](https://github.com/yargs/yargs-parser/compare/v11.1.0...v11.1.1) (2018-11-19) |
31
index.js
@@ -12,2 +12,3 @@ var camelCase = require('camelcase') | ||
args = tokenizeArgString(args) | ||
// aliases might have transitive relationships, normalize this. | ||
@@ -203,3 +204,3 @@ var aliases = combineAliases(opts.alias || {}) | ||
} else { | ||
setArg(key, defaultForType(guessType(key, flags))) | ||
setArg(key, defaultValue(key)) | ||
} | ||
@@ -224,3 +225,3 @@ } | ||
} else { | ||
setArg(key, defaultForType(guessType(key, flags))) | ||
setArg(key, defaultValue(key)) | ||
} | ||
@@ -272,3 +273,3 @@ } else if (arg.match(/^-[^-]+/) && !arg.match(negative)) { | ||
} else { | ||
setArg(letters[j], defaultForType(guessType(letters[j], flags))) | ||
setArg(letters[j], defaultValue(letters[j])) | ||
} | ||
@@ -299,3 +300,3 @@ } | ||
} else { | ||
setArg(key, defaultForType(guessType(key, flags))) | ||
setArg(key, defaultValue(key)) | ||
} | ||
@@ -458,2 +459,10 @@ } | ||
function processValue (key, val) { | ||
// strings may be quoted, clean this up as we assign values. | ||
if (typeof val === 'string' && | ||
(val[0] === "'" || val[0] === '"') && | ||
val[val.length - 1] === val[0] | ||
) { | ||
val = val.substring(1, val.length - 1) | ||
} | ||
// handle parsing boolean arguments --foo=true --bar false. | ||
@@ -749,2 +758,14 @@ if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) { | ||
// make a best effor to pick a default value | ||
// for an option based on name and type. | ||
function defaultValue (key) { | ||
if (!checkAllAliases(key, flags.bools) && | ||
!checkAllAliases(key, flags.counts) && | ||
`${key}` in defaults) { | ||
return defaults[key] | ||
} else { | ||
return defaultForType(guessType(key)) | ||
} | ||
} | ||
// return a default value, given the type of a flag., | ||
@@ -764,3 +785,3 @@ // e.g., key of type 'string' will default to '', rather than 'true'. | ||
// given a flag, enforce a default type. | ||
function guessType (key, flags) { | ||
function guessType (key) { | ||
var type = 'boolean' | ||
@@ -767,0 +788,0 @@ |
@@ -30,6 +30,4 @@ // take an un-split argv string and tokenize it. | ||
opening = null | ||
continue | ||
} else if ((c === "'" || c === '"') && !opening) { | ||
opening = c | ||
continue | ||
} | ||
@@ -36,0 +34,0 @@ |
{ | ||
"name": "yargs-parser", | ||
"version": "11.1.1", | ||
"version": "12.0.0", | ||
"description": "the mighty option parser used by yargs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -76,3 +76,2 @@ # yargs-parser | ||
* `opts.number`: keys should be treated as numbers. | ||
* `opts['--']`: arguments after the end-of-options flag `--` will be set to the `argv.['--']` array instead of being set to the `argv._` array. | ||
@@ -79,0 +78,0 @@ **returns:** |
53259
796
351