Skip to content

Commit

Permalink
fix: boolean numeric short option (yargs#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
QmarkC authored Aug 5, 2020
1 parent 99cdf5d commit f600082
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/yargs-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ export class YargsParser {

// current letter is an alphabetic character and next value is a number
if (/[A-Za-z]/.test(letters[j]) &&
/^-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
/^-?\d+(\.\d*)?(e-?\d+)?$/.test(next) &&
checkAllAliases(next, flags.bools) === false) {
setArg(letters[j], next)
broken = true
break
Expand Down
20 changes: 20 additions & 0 deletions test/yargs-parser.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,26 @@ describe('yargs-parser', function () {
result.should.have.property('b').that.is.a('boolean').and.is.true // eslint-disable-line
result.should.have.property('_').and.deep.equal([123])
})

// Fixes: https://github.com/yargs/yargs-parser/issues/283
it('should set boolean numeric option, with numeric option at the end of a group', function () {
const result = parser(['-x1'], { boolean: ['x', '1'] })
expect(result).to.have.property('x', true)
expect(result).to.have.property('1', true)
})

it('should set boolean numeric option, with numeric option at the start of a group', function () {
const result = parser(['-1x'], { boolean: ['x', '1'] })
expect(result).to.have.property('x', true)
expect(result).to.have.property('1', true)
})

it('should set boolean numeric option, with numeric option as part of a group', function () {
const result = parser(['-x1b'], { boolean: ['x', '1', 'b'] })
expect(result).to.have.property('x', true)
expect(result).to.have.property('1', true)
expect(result).to.have.property('b', true)
})
})

describe('defaults', function () {
Expand Down

0 comments on commit f600082

Please sign in to comment.