Skip to content

Commit ee56e31

Browse files
coderaiserbcoe
authored andcommitted
fix: handling of one char alias (#139)
1 parent 68dd3a1 commit ee56e31

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ function parse (args, opts) {
696696
})
697697
// For "--optionName", also set argv['option-name']
698698
flags.aliases[key].concat(key).forEach(function (x) {
699-
if (/[A-Z]/.test(x) && configuration['camel-case-expansion']) {
699+
if (x.length > 1 && /[A-Z]/.test(x) && configuration['camel-case-expansion']) {
700700
var c = decamelize(x, '-')
701701
if (c !== key && flags.aliases[key].indexOf(c) === -1) {
702702
flags.aliases[key].push(c)

test/yargs-parser.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,21 @@ describe('yargs-parser', function () {
12181218
result.should.have.property('someOption', 'asdf')
12191219
})
12201220

1221+
it('should not apply camel-case logic to 1-character options', function () {
1222+
var result = parser(['-p', 'hello'], {
1223+
alias: {
1224+
p: 'parallel',
1225+
P: 'parallel-series'
1226+
}
1227+
})
1228+
1229+
result.should.not.have.property('P', 'hello')
1230+
result.should.not.have.property('parallel-series', 'hello')
1231+
result.should.not.have.property('parallelSeries', 'hello')
1232+
result.should.have.property('parallel', 'hello')
1233+
result.should.have.property('p', 'hello')
1234+
})
1235+
12211236
it('should provide aliases of options with dashes as camelCase properties', function () {
12221237
var result = parser([], {
12231238
alias: {

0 commit comments

Comments
 (0)