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 c
(cmd *cobra.Command, args []string, toComplete string)
| 186 | // named kubectl-get_all, the completion file should be named kubectl_complete-get_all. The completion |
| 187 | // executable must have executable permissions set on it and must be on $PATH. |
| 188 | func pluginCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 189 | // Recreate the plugin name from the commandPath |
| 190 | pluginName := strings.ReplaceAll(strings.ReplaceAll(cmd.CommandPath(), "-", "_"), " ", "-") |
| 191 | |
| 192 | path, found := lookupCompletionExec(pluginName) |
| 193 | if !found { |
| 194 | cobra.CompDebugln(fmt.Sprintf("Plugin %s does not provide a matching completion executable", pluginName), true) |
| 195 | return nil, cobra.ShellCompDirectiveDefault |
| 196 | } |
| 197 | |
| 198 | args = append(args, toComplete) |
| 199 | cobra.CompDebugln(fmt.Sprintf("About to call: %s %s", path, strings.Join(args, " ")), true) |
| 200 | return getPluginCompletions(path, args, os.Environ()) |
| 201 | } |
| 202 | |
| 203 | // lookupCompletionExec will look for the existence of an executable |
| 204 | // that can provide completion for the given plugin name. |
nothing calls this directly
no test coverage detected
searching dependent graphs…