Skip to content

Preserve argument context when expanding short options - #175

Merged
inhere merged 1 commit into
gookit:masterfrom
rupayon123:fix/short-expansion-argument-context-20261028
Oct 28, 2026
Merged

inhere merged 1 commit into
gookit:masterfrom
rupayon123:fix/short-expansion-argument-context-20261028

Conversation

@rupayon123

Copy link
Copy Markdown
Contributor

With enhanced short options enabled, --name -ab currently expands -ab before it can be consumed as the value of --name. It changes the value to -a and enables -b. The same preprocessing changes literal arguments after -- and options belonging to a later subcommand.

Keep normalization inside the active argument context: preserve the next token of a known value-taking option, and stop at the existing terminator, subcommand boundary, or first positional argument when reordering is disabled. Existing registered numeric short aliases, boolean groups and attached-value forms keep working.

The regression tests exercise the public parser at both enhancement levels, with reordering enabled and disabled. They cover values, positional tails, numeric aliases, and unknown/mixed groups. I also verified the built CLI with pipes and real terminal input/output.

Validation on macOS arm64 with Go 1.26.0:

  • Focused tests, full coverage suite, race suite, go vet ./..., go build ./..., and go mod tidy -diff pass. The full suites include the native terminal tests.
  • Staticcheck reports the same 12 existing findings on the base and this patch, with no new findings.
  • The test environment's inherited NO_COLOR=1 makes the existing TestVerbose fail on both the base and patch. Running with that variable unset passes the full suite.

The Linux/Go version matrix still needs CI.

@inhere
inhere merged commit c4bd753 into gookit:master Oct 28, 2026
7 checks passed
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.

2 participants