Skip to content

Commit

Permalink
fix: handling of one char alias (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser authored and bcoe committed Nov 9, 2018
1 parent 68dd3a1 commit ee56e31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ function parse (args, opts) {
})
// For "--optionName", also set argv['option-name']
flags.aliases[key].concat(key).forEach(function (x) {
if (/[A-Z]/.test(x) && configuration['camel-case-expansion']) {
if (x.length > 1 && /[A-Z]/.test(x) && configuration['camel-case-expansion']) {
var c = decamelize(x, '-')
if (c !== key && flags.aliases[key].indexOf(c) === -1) {
flags.aliases[key].push(c)
Expand Down
15 changes: 15 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,21 @@ describe('yargs-parser', function () {
result.should.have.property('someOption', 'asdf')
})

it('should not apply camel-case logic to 1-character options', function () {
var result = parser(['-p', 'hello'], {
alias: {
p: 'parallel',
P: 'parallel-series'
}
})

result.should.not.have.property('P', 'hello')
result.should.not.have.property('parallel-series', 'hello')
result.should.not.have.property('parallelSeries', 'hello')
result.should.have.property('parallel', 'hello')
result.should.have.property('p', 'hello')
})

it('should provide aliases of options with dashes as camelCase properties', function () {
var result = parser([], {
alias: {
Expand Down

0 comments on commit ee56e31

Please sign in to comment.