Merge pull request #31427 from tisonkun/resolve-todo

Check plugin name is not used
pull/31710/head
Evans Mungai 8 months ago committed by GitHub
commit 2e2cb05855
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -132,7 +132,13 @@ func loadCLIPlugins(baseCmd *cobra.Command, out io.Writer) {
DisableFlagParsing: true, DisableFlagParsing: true,
} }
// TODO: Make sure a command with this name does not already exist. for _, cmd := range baseCmd.Commands() {
if cmd.Name() == c.Name() {
slog.Error("failed to load plugins: name conflicts", slog.String("name", c.Name()))
return
}
}
baseCmd.AddCommand(c) baseCmd.AddCommand(c)
// For completion, we try to load more details about the plugins so as to allow for command and // For completion, we try to load more details about the plugins so as to allow for command and

@ -114,9 +114,9 @@ func TestLoadCLIPlugins(t *testing.T) {
}{ }{
{"args", "echo args", "This echos args", "-a -b -c\n", []string{"-a", "-b", "-c"}, 0}, {"args", "echo args", "This echos args", "-a -b -c\n", []string{"-a", "-b", "-c"}, 0},
{"echo", "echo stuff", "This echos stuff", "hello\n", []string{}, 0}, {"echo", "echo stuff", "This echos stuff", "hello\n", []string{}, 0},
{"env", "env stuff", "show the env", "HELM_PLUGIN_NAME=env\n", []string{}, 0},
{"exitwith", "exitwith code", "This exits with the specified exit code", "", []string{"2"}, 2}, {"exitwith", "exitwith code", "This exits with the specified exit code", "", []string{"2"}, 2},
{"fullenv", "show env vars", "show all env vars", fullEnvOutput, []string{}, 0}, {"fullenv", "show env vars", "show all env vars", fullEnvOutput, []string{}, 0},
{"shortenv", "env stuff", "show the env", "HELM_PLUGIN_NAME=shortenv\n", []string{}, 0},
} }
pluginCmds := cmd.Commands() pluginCmds := cmd.Commands()
@ -254,10 +254,6 @@ func TestLoadCLIPluginsForCompletion(t *testing.T) {
tests := []staticCompletionDetails{ tests := []staticCompletionDetails{
{"args", []string{}, []string{}, []staticCompletionDetails{}}, {"args", []string{}, []string{}, []staticCompletionDetails{}},
{"echo", []string{}, []string{}, []staticCompletionDetails{}}, {"echo", []string{}, []string{}, []staticCompletionDetails{}},
{"env", []string{}, []string{"global"}, []staticCompletionDetails{
{"list", []string{}, []string{"a", "all", "log"}, []staticCompletionDetails{}},
{"remove", []string{"all", "one"}, []string{}, []staticCompletionDetails{}},
}},
{"exitwith", []string{}, []string{}, []staticCompletionDetails{ {"exitwith", []string{}, []string{}, []staticCompletionDetails{
{"code", []string{}, []string{"a", "b"}, []staticCompletionDetails{}}, {"code", []string{}, []string{"a", "b"}, []staticCompletionDetails{}},
}}, }},
@ -268,6 +264,10 @@ func TestLoadCLIPluginsForCompletion(t *testing.T) {
{"more", []string{"one", "two"}, []string{"b", "ball"}, []staticCompletionDetails{}}, {"more", []string{"one", "two"}, []string{"b", "ball"}, []staticCompletionDetails{}},
}}, }},
}}, }},
{"shortenv", []string{}, []string{"global"}, []staticCompletionDetails{
{"list", []string{}, []string{"a", "all", "log"}, []staticCompletionDetails{}},
{"remove", []string{"all", "one"}, []string{}, []staticCompletionDetails{}},
}},
} }
checkCommand(t, cmd.Commands(), tests) checkCommand(t, cmd.Commands(), tests)
} }

@ -1,4 +1,4 @@
name: env name: shortenv
commands: commands:
- name: list - name: list
flags: flags:

@ -1,6 +1,6 @@
--- ---
apiVersion: v1 apiVersion: v1
name: env name: shortenv
type: cli/v1 type: cli/v1
runtime: subprocess runtime: subprocess
config: config:

@ -1,7 +1,7 @@
args echo args args echo args
echo echo stuff echo echo stuff
env env stuff
exitwith exitwith code exitwith exitwith code
fullenv show env vars fullenv show env vars
shortenv env stuff
:4 :4
Completion ended with directive: ShellCompDirectiveNoFileComp Completion ended with directive: ShellCompDirectiveNoFileComp

@ -1,6 +1,6 @@
echo echo stuff echo echo stuff
env env stuff
exitwith exitwith code exitwith exitwith code
fullenv show env vars fullenv show env vars
shortenv env stuff
:4 :4
Completion ended with directive: ShellCompDirectiveNoFileComp Completion ended with directive: ShellCompDirectiveNoFileComp

Loading…
Cancel
Save