Replaces getRoot function by simply using cmd.Root() builtin
This commit is contained in:
parent
12774baedc
commit
c0bd4fd0e1
1 changed files with 2 additions and 15 deletions
|
@ -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) {
|
func bashCompletionCmdF(cmd *cobra.Command, args []string) {
|
||||||
root := getRoot(cmd)
|
if err := cmd.Root().GenBashCompletion(os.Stdout); err != nil {
|
||||||
if err := root.GenBashCompletion(os.Stdout); err != nil {
|
|
||||||
ErrorAndExit(cmd, fmt.Errorf("unable to generate completions: %w", err))
|
ErrorAndExit(cmd, fmt.Errorf("unable to generate completions: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func zshCompletionCmdF(cmd *cobra.Command, args []string) {
|
func zshCompletionCmdF(cmd *cobra.Command, args []string) {
|
||||||
root := getRoot(cmd)
|
if err := cmd.Root().GenZshCompletion(os.Stdout); err != nil {
|
||||||
if err := root.GenZshCompletion(os.Stdout); err != nil {
|
|
||||||
ErrorAndExit(cmd, fmt.Errorf("unable to generate completions: %w", err))
|
ErrorAndExit(cmd, fmt.Errorf("unable to generate completions: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue