func GetPluginCommandGroup(kubectl *cobra.Command) templates.CommandGroup { … } // SetupPluginCompletion adds a Cobra command to the command tree for each // plugin. This is only done when performing shell completion that relate // to plugins. func SetupPluginCompletion(cmd *cobra.Command, args []string) { … } // registerPluginCommand allows adding Cobra command to the command tree or extracting them for usage in // e.g. the help function or for registering the completion function func registerPluginCommands(kubectl *cobra.Command, list bool) (cmds []*cobra.Command) { … } // pluginCompletion deals with shell completion beyond the plugin name, it allows to complete // plugin arguments and flags. // It will look on $PATH for a specific executable file that will provide completions // for the plugin in question. // // When called, this completion executable should print the completion choices to stdout. // The arguments passed to the executable file will be the arguments for the plugin currently // on the command-line. For example, if a user types: // // kubectl myplugin arg1 arg2 a<TAB> // // the completion executable will be called with arguments: "arg1" "arg2" "a". // And if a user types: // // kubectl myplugin arg1 arg2 <TAB> // // the completion executable will be called with arguments: "arg1" "arg2" "". Notice the empty // last argument which indicates that a new word should be completed but that the user has not // typed anything for it yet. // // Kubectl's plugin completion logic supports Cobra's ShellCompDirective system. This means a plugin // can optionally print :<value of a shell completion directive> as its very last line to provide // directives to the shell on how to perform completion. If this directive is not present, the // cobra.ShellCompDirectiveDefault will be used. Please see Cobra's documentation for more details: // https://github.com/spf13/cobra/blob/master/shell_completions.md#dynamic-completion-of-nouns // // The completion executable should be named kubectl_complete-<plugin>. For example, for a plugin // named kubectl-get_all, the completion file should be named kubectl_complete-get_all. The completion // executable must have executable permissions set on it and must be on $PATH. func pluginCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { … } // lookupCompletionExec will look for the existence of an executable // that can provide completion for the given plugin name. // The first filepath to match is returned, or a boolean false if // such an executable is not found. func lookupCompletionExec(pluginName string) (string, bool) { … } // getPluginCompletions receives an executable's filepath, a slice // of arguments, and a slice of environment variables // to relay to the executable. // The executable is responsible for printing the completions of the // plugin for the current set of arguments. func getPluginCompletions(executablePath string, cmdArgs, environment []string) ([]string, cobra.ShellCompDirective) { … }