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

allowableValues doesn't work with array type #428

Closed
liuxh0 opened this issue Jul 22, 2020 · 0 comments · Fixed by #429
Closed

allowableValues doesn't work with array type #428

liuxh0 opened this issue Jul 22, 2020 · 0 comments · Fixed by #429

Comments

@liuxh0
Copy link
Contributor

liuxh0 commented Jul 22, 2020

When I define an array-typed option with allowableValues, the validation doesn't seem to work properly.

Semantically I think this should be interpreted that this option accepts multiple values and each of the values should be allowable.

Currently, the validity is checked by this method:

private checkIfAllowable(allowable: ICommandOptionAllowableValues, input: string): boolean {
let matchFound: boolean = false;
for (const value of allowable.values) {
const flags = allowable.caseSensitive ? "g" : "ig";
if (new RegExp(value, flags).test(input)) {
matchFound = true;
break;
}
}
return matchFound;
}

If the option is of type array, input is also of type array. Although the parameter of RegExp.test() should be of type string, it will somehow first convert other types to string and then perform regular expression match.

I want to extend the support for array. I offer to create a PR if this concept is okay.

@zFernand0 zFernand0 linked a pull request Jul 30, 2020 that will close this issue
@ghost ghost closed this as completed in #429 Aug 6, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant