Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): refactor CLI argument parser (#3765)
This commit refactors the argument parser we use for our CLI module. Doing so fixes an issue with certain flags supported by Jest which can be passed multiple times. For instance, in the following example: ``` jest --coverage --reporters="default" --reporters="jest-junit" ``` all of the values for the `--reporters` flag ("default" and "jest-junit") should be collected into an array of values, instead of simply recording whichever value is farther to the right (Stencil's behavior before this commit). To support passing such arguments to the `stencil test` subcommand this commit adds a new recursive-descent parser in `src/cli/parse-flags.ts` to replace the somewhat ad-hoc approach that was there previously. It parses the following grammar: ``` CLIArguments → "" | CLITerm ( " " CLITerm )* ; CLITerm → EqualsArg | AliasEqualsArg | AliasArg | NegativeDashArg | NegativeArg | SimpleArg ; EqualsArg → "--" ArgName "=" CLIValue ; AliasEqualsArg → "-" AliasName "=" CLIValue ; AliasArg → "-" AliasName ( " " CLIValue )? ; NegativeDashArg → "--no-" ArgName ; NegativeArg → "--no" ArgName ; SimpleArg → "--" ArgName ( " " CLIValue )? ; ArgName → /^[a-zA-Z-]+$/ ; AliasName → /^[a-z]{1}$/ ; CLIValue → '"' /^[a-zA-Z0-9]+$/ '"' | /^[a-zA-Z0-9]+$/ ; ``` The regexes are a little fuzzy, but this is sort of an informal presentation, and additionally there are other constraints implemented in the code which handles all of these different terms. Refactoring this to use a proper parser (albeit a pretty simple one) allows our implementation to much more clearly conform to this defined grammar, and should hopefully both help us avoid other bugs in the future and be easier to maintain. See #3712 for more details on the issues with the `--reporters` flag in particular.
- Loading branch information