Skip to content

Commit

Permalink
fix: print valid flag values in error message when using exactlyOne (
Browse files Browse the repository at this point in the history
…#349)

* fix: print valid flag values in error message when using `exactlyOne`

* fix: print flag in error msg
  • Loading branch information
cristiand391 committed Feb 25, 2022
1 parent d7067d1 commit ddcaeb2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/parser/validate.ts
Expand Up @@ -49,8 +49,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/parser/parse.test.ts
Expand Up @@ -812,15 +812,15 @@ See more help with --help`)
try {
await 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']}),
},
})
} catch (error: any) {
message = error.message
}

expect(message).to.equal('Exactly one of the following must be provided: b,a,r')
expect(message).to.equal('Exactly one of the following must be provided: --bar, --foo')
})

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

0 comments on commit ddcaeb2

Please sign in to comment.