Skip to content

Commit

Permalink
merge PR187
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Jul 12, 2019
1 parent 17ca3bd commit 26643e0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions index.js
Expand Up @@ -470,7 +470,9 @@ function parse (args, opts) {
if (typeof val === 'string') val = val === 'true'
}

var value = maybeCoerceNumber(key, val)
var value = Array.isArray(val)
? val.map(function (v) { return maybeCoerceNumber(key, v) })
: maybeCoerceNumber(key, val)

// increment a count given as arg (either no value or value parsed as boolean)
if (checkAllAliases(key, flags.counts) && (isUndefined(value) || typeof value === 'boolean')) {
Expand All @@ -486,7 +488,7 @@ function parse (args, opts) {
}

function maybeCoerceNumber (key, value) {
if (!checkAllAliases(key, flags.strings)) {
if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.bools) && !Array.isArray(value)) {
const shouldCoerceNumber = isNumber(value) && configuration['parse-numbers'] && (
Number.isSafeInteger(Math.floor(value))
)
Expand Down
2 changes: 1 addition & 1 deletion test/yargs-parser.js
Expand Up @@ -2453,7 +2453,7 @@ describe('yargs-parser', function () {
'flatten-duplicate-arrays': false
}
})
parsed['x'].should.deep.equal([1, 2, 3])
parsed['x'].should.deep.equal([[1], [2], [3]])
})
it('[-x 1 2 3 -x 2 3 4] => [[1, 2, 3], [ 2, 3, 4]]', function () {
var parsed = parser('-x 1 2 3 -x 2 3 4', {
Expand Down

0 comments on commit 26643e0

Please sign in to comment.