Repository navigation
Conversation
The shell completion scripts read one suggestion per line, as "name:usage" or "name". A command or flag whose usage spans several lines therefore had every line after the first offered as a suggestion of its own. Write only the first line of the usage, as cobra does for its completion descriptions.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
What this PR does / why we need it:
The completion scripts for bash, zsh, fish and PowerShell read
--generate-shell-completionoutput one suggestion per line, in the formname:usageorname. A command or flag whoseUsagehas more than one line therefore writes extra lines, and the shell treats each of them as a suggestion of its own. Take this command:Here
demo <TAB>in bash offersserve,and,keep,it,running,stopandhelp. The second line splits into words because bash'scompgen -Wsplits on whitespace. The same happens with flag usage when completing--<TAB>.help.go: addcompletionUsage, which returns the usage up to the first\ror\n, and use it inprintCommandSuggestionsandprintFlagSuggestions. Cobra does the same for its completion descriptions and keeps only the first line. Help output still shows the full usage.completion_test.go: addTestCompletionMultilineUsage. It checks the exact command and flag completion output for usages that contain\n,\n\nand\r\n.Which issue(s) this PR fixes:
None filed. I found this on current main while looking at how the completion output is framed. I didn't find a matching issue or a competing PR.
Special notes for your reviewer:
Help output is unchanged. Only the shell completion descriptions are cut to their first line.
Testing
go test -run TestCompletionMultilineUsage .fails on main (192ed0b) in both cases and passes with this change./bin/bash3.2: built the example above against main and against this branch, sourced the output ofdemo completion bash(with a stub_get_comp_words_by_ref, since bash-completion isn't installed), then called the completion function withCOMP_WORDS=(./demo ""). On mainCOMPREPLYisserve and keep it running stop help. With this change it'sserve stop help.make generate,make vet,make test,make test GFLAGS='--tags urfave_cli_no_template',make check-binary-size,make diffcheck,make v3diff,gofmt -l .,goimports -l .andgolangci-lint run(v2 latest) pass. Generated API documentation is unchanged.make gfmrun(gfmrun not installed), and Linux/Windows CI.Release Notes