Skip to content

fix: complete persistent flags in shell completion - #2437

Open
sb123sb123 wants to merge 1 commit into
urfave:mainfrom
sb123sb123:fix/2173-zsh-persistent-flag-completion
Open

sb123sb123 wants to merge 1 commit into
urfave:mainfrom
sb123sb123:fix/2173-zsh-persistent-flag-completion

Conversation

@sb123sb123

Copy link
Copy Markdown

Summary

Fixes #2173.

When shell completion runs for a subcommand, DefaultCompleteWithFlags passed only the command's local flags to the suggestion formatter. Persistent flags defined by an ancestor command are still valid after entering the subcommand, but they were omitted from suggestions, so a prefix such as --conf could not complete to --config.

This change combines visible persistent flags with the command's visible local flags before generating suggestions. The regression test covers a persistent string flag before and after a positional argument, plus the short - prefix used by zsh completion. Existing completion fixtures now mark their intentionally command-local flags with Local: true.

Testing

  • go test . -count=1 -run TestCompletionIncludesPersistentFlagsAfterPositionalArgument
  • go test . -count=1 -run TestPartialFlagCompletionAfterPositionalArgument
  • go test . -count=1 -run TestDefaultCompleteWithFlags
  • go test ./... -count=1
  • go vet ./...
  • gofmt checks and git diff --check

Limitations

  • The initial dependency-resolution attempt could not reach proxy.golang.org; the successful test runs used the existing local module cache with GOPROXY=off.
  • The race suite could not run on the Windows host: the default toolchain has cgo disabled, and enabling cgo failed because gcc is unavailable.
  • golangci-lint, staticcheck, goimports, and gfmrun were not installed on the host.

AI assistance disclosure

This pull request was developed with assistance from OpenAI Codex. The submitting operator reviewed and understood the implementation, tests, verification results, and this description.

Release Notes

Fix shell completion of visible persistent flags on subcommands.

@sb123sb123
sb123sb123 requested a review from a team as a code owner September 22, 2026 00:39

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.

bug: zsh autocompletions

1 participant