Skip to content

Commit ccc3634

Browse files
shadowspawnbcoe
andauthored
fix: preserve negative number handling when short-option-groups:false (#511)
Co-authored-by: Benjamin E. Coe <[email protected]>
1 parent cea8972 commit ccc3634

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/yargs-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class YargsParser {
259259

260260
// -- separated by space.
261261
} else if (arg.match(/^--.+/) || (
262-
!configuration['short-option-groups'] && arg.match(/^-[^-]+/)
262+
!configuration['short-option-groups'] && arg.match(/^-[^-]+/) && !arg.match(negative)
263263
)) {
264264
m = arg.match(/^--?(.+)/)
265265
if (m !== null && Array.isArray(m) && m.length >= 2) {

test/yargs-parser.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,6 +2884,24 @@ describe('yargs-parser', function () {
28842884
result.newAliases.should.deep.equal({})
28852885
})
28862886

2887+
it('should treat negative numbers as numbers when "short-option-groups" false', function () {
2888+
// First confirm the normal behaviour, as that is what we expect, and has changed over time.
2889+
const normalResult = parser.detailed([
2890+
'-1'
2891+
])
2892+
normalResult.argv.should.deep.equal({ _: [-1] })
2893+
2894+
const result = parser.detailed([
2895+
'-1'
2896+
], {
2897+
configuration: {
2898+
'short-option-groups': false
2899+
}
2900+
})
2901+
result.argv.should.deep.equal({ _: [-1] })
2902+
})
2903+
2904+
28872905
it('should populate the "--" if populate-- is "true"', function () {
28882906
const result = parser([
28892907
'--name=meowmers', 'bare', '-cats', 'woo', 'moxy',

0 commit comments

Comments
 (0)