From 72a8bfc55979c56eb15810d954399a790d67e71e Mon Sep 17 00:00:00 2001 From: Kazuki Suda Date: Wed, 10 Feb 2021 09:15:17 +0900 Subject: [PATCH] Make clusterctl completion zsh work with sourcing Enabling completion with `clusterctl completion zsh` only supports putting a completion file to `fpath`. This is a breaking change for users currently using sourcing. This change allows users to continue to enable completion via sourcing. --- cmd/clusterctl/cmd/completion.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/clusterctl/cmd/completion.go b/cmd/clusterctl/cmd/completion.go index da391fea2b12..bbf4405c82fe 100644 --- a/cmd/clusterctl/cmd/completion.go +++ b/cmd/clusterctl/cmd/completion.go @@ -131,7 +131,10 @@ func runCompletionZsh(out io.Writer, cmd *cobra.Command) error { if err != nil { return err } - fmt.Fprintf(out, "%s\n%s%s", string(line), completionBoilerPlate, b.String()) + fmt.Fprintf(out, "%s\n%s%s\n", string(line), completionBoilerPlate, b.String()) + + // Cobra doesn't source zsh completion file, explicitly doing it here + fmt.Fprintln(out, "compdef _clusterctl clusterctl") return nil }