Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/yargs-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,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)) {
Expand Down
26 changes: 23 additions & 3 deletions test/yargs-parser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,23 +1493,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']
Expand All @@ -1527,6 +1535,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 () {
Expand Down
Loading