Skip to content

Commit

Permalink
Fix issue with non-specified values
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Aug 9, 2022
1 parent 01d52ab commit c020531
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions scripts/utils/options.test.ts
Expand Up @@ -85,6 +85,14 @@ describe('getOptions', () => {
).toThrow(/Unexpected value/);
});

it('allows arbitrary string options when values are not specified', () => {
expect(
getOptions(createCommand(), allOptions, ['command', 'name', '--fourth', 'random'])
).toMatchObject({
fourth: 'random',
});
});

it('deals with multiple string options', () => {
expect(
getOptions(createCommand(), allOptions, ['command', 'name', '--fifth', 'a'])
Expand All @@ -104,6 +112,14 @@ describe('getOptions', () => {
getOptions(createCommand(), allOptions, ['command', 'name', '--fifth', 'random'])
).toThrow(/Unexpected value/);
});

it('allows arbitrary multiple string options when values are not specified', () => {
expect(
getOptions(createCommand(), allOptions, ['command', 'name', '--sixth', 'random'])
).toMatchObject({
sixth: ['random'],
});
});
});

describe('areOptionsSatisfied', () => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils/options.ts
Expand Up @@ -123,7 +123,7 @@ export function getOptions<TOptions extends OptionSpecifier>(
if (option.type === 'boolean') return acc.option(flags, option.description, !!option.inverse);

const checkStringValue = (raw: string) => {
if (!option.values.includes(raw)) {
if (option.values && !option.values.includes(raw)) {
const possibleOptions = chalk.cyan(option.values.join(', '));
throw new Error(
dedent`Unexpected value '${chalk.yellow(raw)}' for option '${chalk.magenta(key)}'.
Expand Down

0 comments on commit c020531

Please sign in to comment.