Skip to content

Commit

Permalink
fix: make positionals in -- count towards validation (#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Sep 13, 2020
1 parent 088ce6b commit eb2b29d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/validation.ts
Expand Up @@ -20,7 +20,8 @@ export function validation (yargs: YargsInstance, usage: UsageInstance, y18n: Y1
self.nonOptionCount = function nonOptionCount (argv) {
const demandedCommands = yargs.getDemandedCommands()
// don't count currently executing commands
const _s = argv._.length - yargs.getContext().commands.length
const positionalCount = argv._.length + (argv['--'] ? argv['--'].length : 0)
const _s = positionalCount - yargs.getContext().commands.length

if (demandedCommands._ && (_s < demandedCommands._.min || _s > demandedCommands._.max)) {
if (_s < demandedCommands._.min) {
Expand Down
10 changes: 10 additions & 0 deletions test/validation.cjs
Expand Up @@ -952,6 +952,16 @@ describe('validation tests', () => {
})
.parse()
})

// See: https://github.com/yargs/yargs/issues/1732
it('treats positionals in "--" towards count requirement', () => {
const argv = yargs('--cool man -- batman robin')
.demandCommand(2)
.fail((msg) => {
throw Error(msg)
})
.parse()
})
})

describe('strictCommands', () => {
Expand Down

0 comments on commit eb2b29d

Please sign in to comment.