Skip to content

Commit

Permalink
fix: check aliases when guessing defaults for arguments fixes #41 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Aug 8, 2016
1 parent 350b778 commit f3e4616
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,9 @@ function parse (args, opts) {
function guessType (key, flags) {
var type = 'boolean'

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'

return type
}
Expand Down
30 changes: 30 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1903,4 +1903,34 @@ describe('yargs-parser', function () {
})
})
})

// addresses: https://github.com/yargs/yargs-parser/issues/41
it('defaults to empty array if array option is provided no values', function () {
var parsed = parser(['-f'], {
'alias': {
'f': 'files'
},
'array': ['files']
})
parsed.f.should.deep.equal([])
parsed.files.should.deep.equal([])

parsed = parser(['--files'], {
'alias': {
'f': 'files'
},
'array': ['files']
})
parsed.f.should.deep.equal([])
parsed.files.should.deep.equal([])

parsed = parser(['-f', '-y'], {
'alias': {
'f': 'files'
},
'array': ['files']
})
parsed.f.should.deep.equal([])
parsed.files.should.deep.equal([])
})
})

0 comments on commit f3e4616

Please sign in to comment.