From c0bd4fd0e1b863e18cd6ec6e415d811d97285174 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Mon, 5 Oct 2020 11:58:31 +0200 Subject: [PATCH] Replaces getRoot function by simply using cmd.Root() builtin --- cmd/completion.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/cmd/completion.go b/cmd/completion.go index f9959d9..936546f 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -47,27 +47,14 @@ To configure your zsh shell to load completions for each session, add the above } } -func getRoot(cmd *cobra.Command) *cobra.Command { - root := cmd - for { - if !root.HasParent() { - break - } - root = root.Parent() - } - return root -} - func bashCompletionCmdF(cmd *cobra.Command, args []string) { - root := getRoot(cmd) - if err := root.GenBashCompletion(os.Stdout); err != nil { + if err := cmd.Root().GenBashCompletion(os.Stdout); err != nil { ErrorAndExit(cmd, fmt.Errorf("unable to generate completions: %w", err)) } } func zshCompletionCmdF(cmd *cobra.Command, args []string) { - root := getRoot(cmd) - if err := root.GenZshCompletion(os.Stdout); err != nil { + if err := cmd.Root().GenZshCompletion(os.Stdout); err != nil { ErrorAndExit(cmd, fmt.Errorf("unable to generate completions: %w", err)) } }