Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: boolean numeric short option #294

Merged
merged 4 commits into from Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.ts
Expand Up @@ -333,7 +333,8 @@ function parse (argsInput: ArgsInput, options?: Partial<Options>): DetailedArgum

// 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.js
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