Ignore trailing positional arguments in the global flag parser#2199
Open
aicayzer wants to merge 1 commit into
Open
Ignore trailing positional arguments in the global flag parser#2199aicayzer wants to merge 1 commit into
aicayzer wants to merge 1 commit into
Conversation
The flag parser in common/flags/index.ts runs in a static initialiser at module load and parses process.argv. Once it had seen a --flag, any later token that was neither another flag nor a flag value caused it to throw "Arg neither flag name nor flag value", crashing the entire CLI before yargs ran. yargs accepts positional arguments after flags (for example `dataform run --some-flag value my_project`), so this lightweight parser was rejecting valid argument orderings. Ignore any token that is neither a flag nor a flag value instead of throwing, exactly as already happened for positional arguments before the first flag; yargs remains responsible for parsing positionals. Extract the parsing loop into an exported parseArgv function so it can be unit-tested in isolation, and add common/flags/index_test.ts covering the regression and related orderings. Fixes dataform-co#2198.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
common/flags/index.tsparsesprocess.argvin a static initialiser that runs at module load, before yargs. Once it had seen a--flag, any following token that was neither another flag nor a flag value made it throwArg neither flag name nor flag value: <arg>— crashing the entire CLI for argument orderings that yargs happily accepts, e.g.dataform run --some-flag value my_project.What changed
parseArgv(argv)function so it can be unit-tested in isolation (it previously only ran against the realprocess.argv).common/flags/index_test.tscovering flag/value pairs,--flag=value,--no-prefixes, multiple flags, no flags, and positional arguments both before and after flags (the regression case).Why
Fixes #2198