Skip to content

fix: preserve incomplete short groups for shell completion - #2485

Open
kimjooyoon wants to merge 1 commit into
urfave:mainfrom
kimjooyoon:fix/completion-short-groups
Open

kimjooyoon wants to merge 1 commit into
urfave:mainfrom
kimjooyoon:fix/completion-short-groups

Conversation

@kimjooyoon

@kimjooyoon kimjooyoon commented Oct 22, 2026 •

Copy link
Copy Markdown

What type of PR is this?

  • bug

What this PR does / why we need it:

With UseShortOptionHandling enabled, custom shell completion loses an unfinished grouped flag from cmd.Args(). For example, declare boolean a and string b, then run:

cmd.Run(ctx, []string{"app", "value", "-ab", "--generate-shell-completion"})

A ShellComplete callback reading cmd.Args().Slice() currently receives only ["value"]. After this change it receives ["value", "-ab"], matching the existing handling of an unfinished single flag such as -b.

command_parse.go retains the unparsed tail during shell completion when a short group contains an unknown flag, or its final value-taking flag has no value yet. Normal invocations still return their original errors. Complete groups, including an explicit empty value (-ab=), remain consumed normally.

completion_short_group_test.go checks the callback at the root, child and nested command, with unknown groups and missing ASCII/Unicode final values. It also checks normal errors, parsed values, explicit empty values and that completion does not execute the action.

Which issue(s) this PR fixes:

Independently reproduced on main 10f69fd3c38de86a3bc17810dcb7f818b494f027; no existing matching issue or open PR found in the search before submission.

Special notes for your reviewer:

Authored and tested with a Codex agent on behalf of kimjooyoon. This change adds no dependency and changes no public API. It extends the existing single-flag completion behavior to grouped short flags.

Testing

Local macOS arm64:

  • Same 20 focused cases on original main: 9 fail / 11 pass; with the fix: 20 pass. The nine failures are the three grouped-token cases at each of the root/child/nested commands. The existing single-flag and normal parsing controls pass both.
  • Focused cases pass with Go 1.26.0 and Go 1.27.3.
  • Go 1.27.3: go test ./..., go test -tags urfave_cli_no_template ./..., and go test -race ./... pass.
  • make generate vet check-binary-size v3diff passes; generated public API files remain unchanged. make gfmrun passes the README example check with pinned gfmrun v1.3.3.
  • golangci-lint v2.15.0 reports 0 issues after correcting one test formatting finding.

Upstream test CI passes all six Linux/macOS/Windows × stable/oldstable jobs, and lint CI passes, both on head 5dbdb1037281c390c4f98c144ab82150262bdff9. These passing checks do not assert maintainer review or acceptance.

Release Notes

Preserve unfinished grouped short flags in arguments passed to custom shell completion callbacks.

Authored with Codex. Keep pending grouped tokens available to custom completion callbacks, matching the existing single-flag behavior.

This branch has not been deployed

No deployments
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.

1 participant