Skip to content

Ignore trailing positional arguments in the global flag parser#2199

Open
aicayzer wants to merge 1 commit into
dataform-co:mainfrom
aicayzer:fix/cli-flag-positional-order
Open

Ignore trailing positional arguments in the global flag parser#2199
aicayzer wants to merge 1 commit into
dataform-co:mainfrom
aicayzer:fix/cli-flag-positional-order

Conversation

@aicayzer
Copy link
Copy Markdown

@aicayzer aicayzer commented Jun 7, 2026

Summary

common/flags/index.ts parses process.argv in 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 throw Arg 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

  • Make the parser ignore any token that is neither a flag nor a flag value instead of throwing. Positional arguments (the command and its operands) are left to yargs, exactly as they already were when they appeared before the first flag.
  • Extract the parsing loop into an exported parseArgv(argv) function so it can be unit-tested in isolation (it previously only ran against the real process.argv).
  • Add common/flags/index_test.ts covering 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

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.
@aicayzer aicayzer requested a review from a team as a code owner June 7, 2026 17:46
@aicayzer aicayzer requested review from fafsdafsafs and removed request for a team June 7, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI crashes (Arg neither flag name nor flag value) when a positional argument follows a flag

1 participant