diff --git a/lib/yargs-parser.ts b/lib/yargs-parser.ts index 764ca64e..1b46ed02 100644 --- a/lib/yargs-parser.ts +++ b/lib/yargs-parser.ts @@ -273,7 +273,7 @@ export class YargsParser { } else { next = args[i + 1] - if (next !== undefined && (!next.match(/^-/) || + if (next !== undefined && (!next.match(/^-./) || next.match(negative)) && !checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts)) { diff --git a/test/yargs-parser.cjs b/test/yargs-parser.cjs index 492e3b90..14ce7ce1 100644 --- a/test/yargs-parser.cjs +++ b/test/yargs-parser.cjs @@ -1487,23 +1487,31 @@ describe('yargs-parser', function () { }) describe('-', function () { - it('should set - as value of n', function () { + it('should set - as space separated value of n', function () { const argv = parser(['-n', '-']) argv.should.have.property('n', '-') argv.should.have.property('_').with.length(0) }) - it('should set - as a non-hyphenated value', function () { + it('should set - as a non-hyphenated value (positional)', function () { const argv = parser(['-']) argv.should.have.property('_').and.deep.equal(['-']) }) - it('should set - as a value of f', function () { + it('should set - as an embedded value of f', function () { + // special case dash trailing short option const argv = parser(['-f-']) argv.should.have.property('f', '-') argv.should.have.property('_').with.length(0) }) + it('should set - as an embedded value of f with =', function () { + // usual style for embedded short option value + const argv = parser(['-f=-']) + argv.should.have.property('f', '-') + argv.should.have.property('_').with.length(0) + }) + it('should set b to true and set - as a non-hyphenated value when b is set as a boolean', function () { const argv = parser(['-b', '-'], { boolean: ['b'] @@ -1521,6 +1529,18 @@ describe('yargs-parser', function () { argv.should.have.property('s', '-') argv.should.have.property('_').with.length(0) }) + + it('should set - as space separated value of foo', function () { + const argv = parser(['--foo', '-']) + argv.should.have.property('foo', '-') + argv.should.have.property('_').with.length(0) + }) + + it('should set - as embedded value of foo', function () { + const argv = parser(['--foo=-']) + argv.should.have.property('foo', '-') + argv.should.have.property('_').with.length(0) + }) }) describe('count', function () {