Visitar URL original
fix: suggest no flags after a short flag written out in full by vidigoat · Pull Request #2502 · urfave/cli · GitHub
Skip to content

fix: suggest no flags after a short flag written out in full - #2502

Open
vidigoat wants to merge 1 commit into
urfave:mainfrom
vidigoat:fix/complete-no-flag-after-its-alias
Open

vidigoat wants to merge 1 commit into
urfave:mainfrom
vidigoat:fix/complete-no-flag-after-its-alias

Conversation

@vidigoat

@vidigoat vidigoat commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

printFlagSuggestions trims the dashes from the last argument so that -co can suggest --config. It does the same for a short flag written out in full, so -c suggests every long flag starting with c, including the one -c is an alias of. The shell scripts send the same request for app -c<TAB> and app -c <TAB>, so with a space they offer --config as the value of -c:

&cli.StringFlag{Name: "config", Aliases: []string{"c"}, TakesFile: true},
$ app -c --generate-shell-completion
--config:config file

In bash 5.3, app -c <TAB> fills in app -c --config instead of falling back to file names. fish 4.9.3 offers --config too, and zsh calls _describe with it instead of falling back to _files. Subcommands behave the same way (app sub -c <TAB>).

A short flag written out in full (- plus one letter that names a flag) is now that flag, so printFlagSuggestions prints nothing for it. The shells then fall back to their defaults: file names in bash and zsh. -co, --c and a lone - suggest the same flags as before.

Which issue(s) this PR fixes:

None, found while testing the generated scripts in bash and fish.

Testing

  • New TestCompletionAfterShortFlag: -c on the root command and on a subcommand prints nothing (both fail on main, which prints --config and --count); -co and --c still suggest --config and --count.
  • Checked in bash 5.3 with bash-completion 2.18, fish 4.9.3, and the zsh script's function: app -c <TAB> no longer offers --config, and app --c<TAB> and app -<TAB> are unchanged.
  • make (generate, vet, tests, binary size, gfmrun), make lint and make v3diff pass locally with Go 1.26. go test -race passes, as do the tests with urfave_cli_no_template, urfave_cli_no_docs and urfave_cli_no_suggest.

The change and the test were written with Claude Code (AI).

Release Notes

Shell completion no longer suggests long flags after a short flag such as "-c", which made the shells offer "--config" as the value of "-c".

🤖 Generated with Claude Code

Comment thread scripts/build.go
desiredMaxBinarySize = 2.2
desiredMinBinarySize = 1.49
desiredMaxBinarySize = 2.3
desiredMinBinarySize = 1.59

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this stuff please ty

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks! main already raises the limit (2350b11), so I rebased and the commit is gone from this PR, and from #2501 and #2506 too.

@vidigoat
vidigoat force-pushed the fix/complete-no-flag-after-its-alias branch from 09ecbce to 0dabab6 Compare October 27, 2026 02:28
printFlagSuggestions trims the dashes so that "-co" can suggest
"--config", but it did the same for a short flag such as "-c", and
suggested every long flag starting with "c", including the flag "-c"
belongs to. Since the shell scripts send the same request for
"app -c <TAB>", they offered "--config" as the value of "-c". A short
flag written out in full is that flag, so suggest nothing for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vidigoat
vidigoat force-pushed the fix/complete-no-flag-after-its-alias branch from 0dabab6 to b71450e Compare October 29, 2026 10:19

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.

2 participants