Skip to content

Commit

Permalink
Merge pull request #346 from bcoe/fix-341
Browse files Browse the repository at this point in the history
alias should be applied to camel-case form of argument
  • Loading branch information
bcoe committed Jan 15, 2016
2 parents afed474 + 48ca657 commit 51c0063
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = function (args, opts, y18n) {

extendAliases(opts.key)
extendAliases(opts.alias)
extendAliases(opts.default)

var defaults = opts['default'] || {}
Object.keys(defaults).forEach(function (key) {
Expand Down Expand Up @@ -436,6 +437,11 @@ module.exports = function (args, opts, y18n) {
// extend the aliases list with inferred aliases.
function extendAliases (obj) {
Object.keys(obj || {}).forEach(function (key) {
// short-circuit if we've already added a key
// to the aliases array, for example it might
// exist in both 'opts.default' and 'opts.key'.
if (aliases[key]) return

aliases[key] = [].concat(opts.alias[key] || [])
// For "--option-name", also set argv.optionName
aliases[key].concat(key).forEach(function (x) {
Expand Down
9 changes: 9 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,15 @@ describe('parser tests', function () {
argv2.parse([ ]).flag.should.be.false
})
})

// Fixes: https://github.com/bcoe/yargs/issues/341
it('should apply defaults to camel-case form of argument', function () {
var argv = yargs([])
.default('foo-bar', 99)
.argv

argv.fooBar.should.equal(99)
})
})

it('should define option as boolean and set default to true', function () {
Expand Down

0 comments on commit 51c0063

Please sign in to comment.