Skip to content

fix: use the first line of usage in the generated fish completion script - #2498

Open
vidigoat wants to merge 1 commit into
urfave:mainfrom
vidigoat:fix/fish-script-first-line-usage
Open

vidigoat wants to merge 1 commit into
urfave:mainfrom
vidigoat:fix/fish-script-first-line-usage

Conversation

@vidigoat

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

#2475 cut command and flag usage to its first line in the --generate-shell-completion output, because the completion scripts read one suggestion per line. The static script from ToFishCompletion still writes the whole usage into -d '...':

Flags:    []cli.Flag{&cli.StringFlag{Name: "out", Usage: "write to FILE\nor - for stdout"}},
Commands: []*cli.Command{{Name: "build", Usage: "build the project\nand all its dependencies"}},
complete -c app -n '__fish_app_no_subcommand' -f -l out -r -d 'write to FILE
or - for stdout'

With that script sourced in fish 4.9.3, complete -C "app " prints the second line on its own:

build	build the project
and all its dependencies
test	run tests

and complete -C "app --" does the same with or - for stdout. fish.go now uses completionUsage from #2475 for both the command and the flag descriptions, so the output is build build the project. A usage that starts with a newline gets no -d instead of an empty one. Help output still shows the full usage.

Which issue(s) this PR fixes:

None, found while testing the completion scripts in fish. It is the static-script half of #2475.

Testing

  • New TestFishCompletionUsesFirstLineOfUsage covers \n, \r\n and a usage starting with a newline. It fails on main.
  • The fish part of testdata/expected-help-output.txt now has one-line descriptions for the three multi-line usages it already had (--log, delete and set-a-very-long-name); nothing else in the golden file changes.
  • Checked the generated script in fish 4.9.3 as above.
  • 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 tests were written with Claude Code (AI).

Release Notes

The fish completion script from ToFishCompletion now uses only the first line of a multi-line Usage as the description, like the other completion output.

🤖 Generated with Claude Code

urfave#2475 cut the usage in --generate-shell-completion output to its first
line, because the completion scripts read one suggestion per line.
ToFishCompletion still wrote the whole usage into `-d '...'`, so fish
listed the second line of a command's or flag's usage on its own line.
It now uses completionUsage too.

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:15

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