MCPcopy
hub / github.com/kubernetes/kubectl / pluginCompletion

Function pluginCompletion

pkg/cmd/plugin/plugin_completion.go:188–201  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
188func 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.

Callers

nothing calls this directly

Calls 3

lookupCompletionExecFunction · 0.85
getPluginCompletionsFunction · 0.85
JoinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…