Skip to content

Commit 126a936

Browse files
Xun JiangLyndon-Li
authored andcommitted
Make velero completion zsh command output can be used by source command.
Signed-off-by: Xun Jiang <[email protected]>
1 parent edf76c3 commit 126a936

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

changelogs/unreleased/4914-jxun

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make velero completion zsh command output can be used by `source` command.

pkg/cmd/cli/completion/completion.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ $ velero completion fish > ~/.config/fish/completions/velero.fish
6666
case "bash":
6767
cmd.Root().GenBashCompletion(os.Stdout)
6868
case "zsh":
69-
cmd.Root().GenZshCompletion(os.Stdout)
69+
// # fix #4912
70+
// cobra does not support zsh completion ouptput used by source command
71+
// according to https://github.com/spf13/cobra/issues/1529
72+
// Need to append compdef manually to do that.
73+
zshHead := "#compdef velero\ncompdef _velero velero\n"
74+
out := os.Stdout
75+
out.Write([]byte(zshHead))
76+
77+
cmd.Root().GenZshCompletion(out)
7078
case "fish":
7179
cmd.Root().GenFishCompletion(os.Stdout, true)
7280
default:

0 commit comments

Comments
 (0)