Skip to content

fix: honor TakesFile for every flag type in fish completion - #2500

Open
vidigoat wants to merge 1 commit into
urfave:mainfrom
vidigoat:fix/fish-takes-file-all-flag-types
Open

vidigoat wants to merge 1 commit into
urfave:mainfrom
vidigoat:fix/fish-takes-file-all-flag-types

Conversation

@vidigoat

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

TakesFile is a field of every flag type (FlagBase), and its only reader is the fish completion script, but fishAddFileFlag only checks *StringFlag and *StringSliceFlag. Any other flag with TakesFile: true still gets -f, so fish completes no files for it:

&cli.StringFlag{Name: "config", TakesFile: true},
&cli.GenericFlag{Name: "input", Value: &p, TakesFile: true},
&cli.StringMapFlag{Name: "env-file", TakesFile: true},
complete -c app -n '__fish_app_no_subcommand' -l config -r ...
complete -c app -n '__fish_app_no_subcommand' -f -l input -r ...
complete -c app -n '__fish_app_no_subcommand' -f -l env-file -r ...

In fish 4.9.3, complete -C "app --config " lists the files in the directory, while complete -C "app --input " lists nothing. v2's fishAddFileFlag also handled GenericFlag (and PathFlag, which v3 replaced with StringFlag + TakesFile).

FlagBase now has an unexported takesFile() (TakesFile and the flag takes a value), and fishAddFileFlag checks for it instead of the two concrete types. So every flag type works, there is no API change (make v3diff is clean), and a BoolFlag with TakesFile keeps -f, as it does now, since it has no value to complete.

Which issue(s) this PR fixes:

None, found while testing the generated fish script in fish.

Testing

  • New TestFishCompletionTakesFileForAllFlagTypes (StringFlag, GenericFlag, StringMapFlag, a plain StringFlag and a BoolFlag). It fails on main.
  • Checked the generated script in fish 4.9.3: --input and --env-file now complete files like --config.
  • make (generate, vet, tests, binary size, gfmrun), make lint and make v3diff pass. 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

TakesFile now enables file completion in the fish script for every flag type, not only StringFlag and StringSliceFlag.

🤖 Generated with Claude Code

TakesFile is a field of every flag type, but fishAddFileFlag only
checked StringFlag and StringSliceFlag, so a GenericFlag or
StringMapFlag with TakesFile still got `-f` and fish offered no files
for it. v2 also handled GenericFlag. Flags now report it through an
unexported method on FlagBase; a flag that takes no value (BoolFlag)
keeps `-f`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vidigoat
vidigoat requested a review from a team as a code owner October 24, 2026 17:32

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