From 3b3345483eb8223c54a32fadb80917d4b47e6e0c Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Mon, 24 Jan 2022 16:16:38 -0300 Subject: [PATCH 1/2] fix: print valid flag values in error message when using `exactlyOne` --- src/parser/validate.ts | 4 ++-- test/parser/parse.test.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/parser/validate.ts b/src/parser/validate.ts index 82c80af22..0f9958cf9 100644 --- a/src/parser/validate.ts +++ b/src/parser/validate.ts @@ -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), + ].join(', ')}`) } } diff --git a/test/parser/parse.test.ts b/test/parser/parse.test.ts index 5bea4f4cc..4f55900e6 100644 --- a/test/parser/parse.test.ts +++ b/test/parser/parse.test.ts @@ -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 () => { From 8550a017b3a78a9b518b0d2687ef868815c74ce2 Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Tue, 25 Jan 2022 12:28:16 -0300 Subject: [PATCH 2/2] fix: print flag in error msg --- src/parser/validate.ts | 2 +- test/parser/parse.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parser/validate.ts b/src/parser/validate.ts index 0f9958cf9..e0fccb6bf 100644 --- a/src/parser/validate.ts +++ b/src/parser/validate.ts @@ -49,7 +49,7 @@ 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), + ...new Set(flag.exactlyOne?.map(flag => `--${flag}`)), ].join(', ')}`) } } diff --git a/test/parser/parse.test.ts b/test/parser/parse.test.ts index 4f55900e6..590213924 100644 --- a/test/parser/parse.test.ts +++ b/test/parser/parse.test.ts @@ -820,7 +820,7 @@ See more help with --help`) message = error.message } - expect(message).to.equal('Exactly one of the following must be provided: bar, foo') + expect(message).to.equal('Exactly one of the following must be provided: --bar, --foo') }) it('throws if multiple are set', async () => {