Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: print valid flag values in error message when using exactlyOne (
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiand391 authored Feb 25, 2022
1 parent 5cc8ba1 commit 7b348f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export function validate(parse: {
if (intersection.length === 0) {
// the command's exactlyOne may or may not include itself, so we'll use Set to add + de-dupe
throw new CLIError(`Exactly one of the following must be provided: ${[
...new Set(...flag.exactlyOne || [], flag.name),
].join(',')}`)
...new Set(flag.exactlyOne?.map(flag => `--${flag}`)),
].join(', ')}`)
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,11 @@ See more help with --help`)
expect(() => {
parse([], {
flags: {
foo: flags.string({exactlyOne: ['bar']}),
bar: flags.string({char: 'b', exactlyOne: ['foo']}),
foo: flags.string({exactlyOne: ['bar', 'foo']}),
bar: flags.string({char: 'b', exactlyOne: ['bar', 'foo']}),
},
})
}).to.throw()
}).to.throw('Exactly one of the following must be provided: --bar, --foo')
})

it('throws if multiple are set', () => {
Expand Down

0 comments on commit 7b348f8

Please sign in to comment.