Repository navigation
fix: keep args after -- verbatim in strict mode - #176
Merged
Merged
Conversation
strictFormatArgs normalized every arg, including the positional literals after "--", so "-- --a" reached the command as "-a".
inhere
added a commit
that referenced
this pull request
Oct 29, 2026
…tion values verbatim
The strict mode normalization lived in gcli/util.go while the option metadata it
needs sits in gflag, so it normalized every option-looking token: the value of a
value-taking option was rewritten too.
gcli.SetStrictMode(true)
app.Run([]string{"test", "--name", "--a"}) // before: name="-a", now: "--a"
- Gflag.StrictFormatArgs(args, fs) is the single implementation now, next to
ExpandShortArgs and RearrangeArgs. It keeps the tokens after "--" verbatim (from
#176) and the value token of a known value-taking option, which optMeta reports
with its short alias resolved, so "-n ---deep" is protected like "--name".
- the option token itself is still normalized before its value is copied, so
"---name tom" keeps working; a bool option takes no value, so the token after it
is still normalized as an option; "--" as a value keeps the previous behaviour.
- gcli keeps the mode switch (SetStrictMode also enables EnhanceShort) and calls
the gflag helper; the local strictFormatArgs is gone.
Tests: a table of StrictFormatArgs cases (form, values, terminator, unknown
options, the short alias) and an end-to-end gcli case for the values that look
like options. A 252-cell matrix (strict x EnhanceShort level x reorder x 21 arg
vectors) differs from the previous tree only in the three intended inputs.
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.
#175 made
expandShortArgsleave the arguments after--alone, like the other gflag preprocessors (shorts.go,reorder.go,flags.go). Strict mode'sstrictFormatArgsstill rewrites them, so--abecomes-aand---bbecomes-bbefore the command sees them:The fix stops normalizing at the first
--and appends the rest unchanged. The new test also checks that an option after a positional argument (file ---name tom) is still normalized.One input changes in a way that isn't a fix: if a value-taking option is given
--as its value (--name -- ---b), the---bafter it is no longer rewritten. Strict mode also still rewrites the value of a value-taking option (--name --agives-a). Fixing that would need the option metadata, so I left it out.go test ./...,go vet ./...andgofmtpass on Go 1.26.3.Written with AI assistance (Claude); I have reviewed the change.