Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: print valid flag values in error message when using exactlyOne #349

Merged
merged 3 commits into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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