mirror of
https://github.com/spf13/cobra
synced 2025-04-27 17:17:20 +00:00
Avoid redundant completion output target evaluations
The target is not to be changed while outputting completions, so resolve it only once.
This commit is contained in:
parent
1f495bb3c8
commit
79fb3dd0cf
1 changed files with 4 additions and 3 deletions
|
@ -217,6 +217,7 @@ func (c *Command) initCompleteCmd(args []string) {
|
|||
}
|
||||
|
||||
noDescriptions := (cmd.CalledAs() == ShellCompNoDescRequestCmd)
|
||||
out := finalCmd.OutOrStdout()
|
||||
for _, comp := range completions {
|
||||
if GetActiveHelpConfig(finalCmd) == activeHelpGlobalDisable {
|
||||
// Remove all activeHelp entries in this case
|
||||
|
@ -242,14 +243,14 @@ func (c *Command) initCompleteCmd(args []string) {
|
|||
// although there is no description).
|
||||
comp = strings.TrimSpace(comp)
|
||||
|
||||
// Print each possible completion to stdout for the completion script to consume.
|
||||
fmt.Fprintln(finalCmd.OutOrStdout(), comp)
|
||||
// Print each possible completion to the output for the completion script to consume.
|
||||
fmt.Fprintln(out, comp)
|
||||
}
|
||||
|
||||
// As the last printout, print the completion directive for the completion script to parse.
|
||||
// The directive integer must be that last character following a single colon (:).
|
||||
// The completion script expects :<directive>
|
||||
fmt.Fprintf(finalCmd.OutOrStdout(), ":%d\n", directive)
|
||||
fmt.Fprintf(out, ":%d\n", directive)
|
||||
|
||||
// Print some helpful info to stderr for the user to understand.
|
||||
// Output from stderr must be ignored by the completion script.
|
||||
|
|
Loading…
Add table
Reference in a new issue