fix(cli): make -- terminate flag parsing for all later args - #330
Merged
Conversation
One conflict, the one this branch predicted: filterHelpTokens' doc comment. #312 rewrote the sentence naming runCompile, since dispatch now owns the help-request detection, and this branch appends a paragraph on what a "--" does to the filtering. Both are kept — they describe different halves of the same comment and neither supersedes the other. Everything else merged clean, and the merged tree passes: the terminator work touches parseArgs, root dispatch and filterHelpTokens, none of which #312 moved.
OmarAlJarrah
added a commit
that referenced
this pull request
Aug 9, 2026
The three conflicts this branch predicted, resolved as it said: compile.go keeps #312's specOptions split and gains the pretty field, command_test.go keeps #312's two-list block and gains "pretty", and the README keeps #312's two-command flag table with the -o wording changed and a --pretty row added. #335 also landed on the README since, so its diagnostics and exit-code prose is kept whole rather than reverted to this branch's older paragraph. One interaction the branch could not predict: #330's TestRun_TerminatorAsFlagValue asserts the artifact contains `"name": "Tiny"` — the indented spelling. That test is about which argument "--" became, not about formatting, and -o is compact now, so it matched text it never meant to pin. It decodes the artifact instead, which is what it was always asking.
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
--is supposed to end flag parsing, but morphic only ever shielded one argument with it.parseArgscallsflag.Parsein a loop so flags may appear on either side of the spec path, andParseconsumes a--while reporting nothing about having seen one — so the next round of theloop turns flag parsing straight back on.
morphic compile -- spec.yaml -o out.jsonthereforeexits 0 and writes
out.json, where three operands should be a usage error, andmorphic compile -- -a.yaml -b.yamlanswersflag provided but not defined: -b.yamlabout a filethe user had explicitly marked as not a flag.
The linked issue's motivating case does not hold, and this PR does not repeat it. It says a spec
file whose name begins with
-is "awkward or impossible to pass"; it is neither, becausecompiletakes exactly one operand and one shielded argument is enough —morphic compile -- -dash.yamlcompiles today. The actual defect is the inverse:--is too weak rather thanuseless. Arguments the user marked as operands are still read as flags, so a misuse succeeds
silently and a dash-named extra operand is reported as a bad flag instead of as an extra operand.
The absence is the same at all three places morphic reads an argument list, so all three are
fixed here rather than only the one the issue names:
parseArgssplits at the terminator before the parse loop starts, so everything after it isan operand for the whole invocation instead of for one round.
morphic -- compile spec.yamlused to reportunknown command "--"; themarker is now consumed and
compileis the command.morphic -- -hreportsunknown command "-h"rather than printing help, since past a--nothing is a flag.helpstill routes to help, because it is a command word and never was a flag.
filterHelpTokens—morphic help -- --helpused to reportunknown command "--"; it nownames
--help, andmorphic help -- compileprints compile's help.The split tracks which flags read their value from the following argument, so a
--that a flagasked for stays that flag's value instead of becoming a marker. That is the same distinction
TestRun_HelpFlagAsFlagValuealready pins for--help, and it is why the split takes theFlagSetrather than searching argv for the token.compile's help text gains a paragraph describing the terminator;testdata/compile-help.txtisregenerated to match and changes by exactly those four lines. The README's CLI section is left
alone — it documents the flag table, and
--is not a flag.Test plan
TestRun_TerminatorEndsFlagParsing(new,cmd/morphic/args_test.go) drivesrunover nineargument lists covering all three sites. Six were red before the fix; the three that were
already correct are regression guards against over-correcting.
parseArgs→ the two operand cases; root dispatch → the two--before a command-word cases;filterHelpTokens→ the twohelp --cases. No case covers more than one site.TestRun_TerminatorAsFlagValueis the guard for the other half of the rule:morphic compile -o -- spec.yaml --skip-validatemust write a file literally named--and still parse the flagafter the spec. It passes before and after the fix, and goes red when the split is degraded to a
plain scan for the token — which is how the
FlagSet-aware walk earns its place.TestTakesNextValue_FlagSpellingsandTestSplitAtTerminator_Casesare flat tables over thesplit's own edges: inline
=value, boolean flags, undefined flags,-,---o,-=x, aterminator with nothing after it, and a second terminator that must stay an operand.
gofmt,go vet,golangci-lint,go build, andscripts/check-coverage.shat 100%.Ordering
Branched from
mainand intended to land after #312.cmd/morphic/compile.goandcmd/morphic/main.gomerge cleanly with it. The one conflict isfilterHelpTokens's doc comment,where #312 rewrites the sentence naming
runCompileand this PR appends a sentence about theterminator — take both. Nothing here touches
parseArgs' callers, sovalidateinherits theterminator through the shared bind path with no further change.
Closes #231