Skip to content

Fix fish custom completion arguments - #2338

Merged
dearchap merged 2 commits into
urfave:mainfrom
puneetdixit200:fix-subcommand-shell-complete
May 24, 2026
Merged

Fix fish custom completion arguments#2338
dearchap merged 2 commits into
urfave:mainfrom
puneetdixit200:fix-subcommand-shell-complete

Conversation

@puneetdixit200

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

  • Updates the generated fish completion script so it only forwards the current token when that token starts with -.
  • Makes fish match the bash and zsh behavior for dynamic completions by omitting partial positional tokens from the command invocation.
  • Adds completion coverage for the fish script behavior and nested custom subcommand completion dispatch.

Which issue(s) this PR fixes:

Fixes #2333

Special notes for your reviewer:

The reported callback checks NArg() before printing completions. In fish, the partial positional token was being forwarded before --generate-shell-completion, so callbacks like that saw an argument and returned without output.

Testing

  • GOMODCACHE=$PWD/.gomodcache GOCACHE=$PWD/.gocache go test ./... -run 'TestCompletionFishOmitsPositionalTokenFromDynamicCompletion|TestCompletionSubcommandCustomShellComplete|TestCompletionFishFormat' -count=1\n- GOMODCACHE=$PWD/.gomodcache GOCACHE=$PWD/.gocache go test ./...\n- GOMODCACHE=$PWD/.gomodcache GOCACHE=$PWD/.gocache make vet\n- GOMODCACHE=$PWD/.gomodcache GOCACHE=$PWD/.gocache make test\n- GOMODCACHE=$PWD/.gomodcache GOCACHE=$PWD/.gocache make check-binary-size\n- GOMODCACHE=$PWD/.gomodcache GOCACHE=$PWD/.gocache make generate\n- PATH=$PWD/.local/bin:$PATH GOMODCACHE=/tmp/urfave-cli-gomodcache GOCACHE=/tmp/urfave-cli-gocache make lint\n- PATH=$PWD/.local/bin:$PATH GOMODCACHE=/tmp/urfave-cli-gomodcache GOCACHE=/tmp/urfave-cli-gocache make gfmrun\n- PATH=$PWD/.local/bin:$PATH GOMODCACHE=/tmp/urfave-cli-gomodcache GOCACHE=/tmp/urfave-cli-gocache make v3diff\n- PATH=$PWD/.local/bin:$PATH GOMODCACHE=/tmp/urfave-cli-gomodcache GOCACHE=/tmp/urfave-cli-gocache make diffcheck\n- PATH=$PWD/.local/bin:$PATH GOMODCACHE=/tmp/urfave-cli-gomodcache GOCACHE=/tmp/urfave-cli-gocache golangci-lint run --new-from-rev=upstream/main\n- git diff --check\n\nNote: on macOS arm64, make ensure-gfmrun could not download the gfmrun v1.3.0 release asset because GitHub returned 404, so I installed gfmrun v1.3.0 from source locally before running make gfmrun.\n\n## Release Notes\n\nrelease-note\nFixed fish shell completion for custom subcommand completions.\n

@puneetdixit200
puneetdixit200 requested a review from a team as a code owner May 22, 2026 01:02
@TLINDEN

TLINDEN commented May 22, 2026

Copy link
Copy Markdown

In #2333 I am using bash completion, are you sure, this PR would really fix this too?

@puneetdixit200

Copy link
Copy Markdown
Contributor Author

Yes. The runtime change is fish-only because bash already omits the partial positional token before invoking --generate-shell-completion; the bug was that fish did not match that behavior. I added explicit bash coverage in 1549407 so the #2333 callback shape is covered while keeping the fish regression test in place. The latest CI is green across the Go stable/oldstable matrix.

@dearchap
dearchap merged commit db7128f into urfave:main May 24, 2026
9 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.

Custom shell completion doesn't work

3 participants