diff --git a/cmd/helm/load_plugins.go b/cmd/helm/load_plugins.go index 23b1b7ff4..8ac0779e5 100644 --- a/cmd/helm/load_plugins.go +++ b/cmd/helm/load_plugins.go @@ -170,7 +170,9 @@ func manuallyProcessArgs(args []string) ([]string, []string) { return v } } - return "" + // Return something different than what we received by adding a random prefix. + // We cannot simply return an empty string as v could be an empty string itself. + return fmt.Sprintf("x%s", v) } for i := 0; i < len(args); i++ { diff --git a/cmd/helm/plugin_test.go b/cmd/helm/plugin_test.go index cbaf05321..b31aa140c 100644 --- a/cmd/helm/plugin_test.go +++ b/cmd/helm/plugin_test.go @@ -116,6 +116,8 @@ func TestLoadPlugins(t *testing.T) { {"env", "env stuff", "show the env", "env\n", []string{}, 0}, {"exitwith", "exitwith code", "This exits with the specified exit code", "", []string{"2"}, 2}, {"fullenv", "show env vars", "show all env vars", envs + "\n", []string{}, 0}, + // Test that empty arguments are passed to the plugin + {"numargs", "echo num args", "echo number of arguments received", "3\n", []string{"-a", "", "-b"}, 0}, } plugins := cmd.Commands() @@ -271,6 +273,7 @@ func TestLoadPluginsForCompletion(t *testing.T) { {"more", []string{"one", "two"}, []string{"b", "ball"}, []staticCompletionDetails{}}, }}, }}, + {"numargs", []string{}, []string{}, []staticCompletionDetails{}}, } checkCommand(t, cmd.Commands(), tests) } diff --git a/cmd/helm/testdata/helmhome/helm/plugins/numargs/numargs.sh b/cmd/helm/testdata/helmhome/helm/plugins/numargs/numargs.sh new file mode 100755 index 000000000..11d0c56e8 --- /dev/null +++ b/cmd/helm/testdata/helmhome/helm/plugins/numargs/numargs.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo $# diff --git a/cmd/helm/testdata/helmhome/helm/plugins/numargs/plugin.yaml b/cmd/helm/testdata/helmhome/helm/plugins/numargs/plugin.yaml new file mode 100644 index 000000000..df9ab1b25 --- /dev/null +++ b/cmd/helm/testdata/helmhome/helm/plugins/numargs/plugin.yaml @@ -0,0 +1,4 @@ +name: numargs +usage: "echo num args" +description: "echo number of arguments received" +command: "$HELM_PLUGIN_DIR/numargs.sh" diff --git a/cmd/helm/testdata/output/plugin_list_comp.txt b/cmd/helm/testdata/output/plugin_list_comp.txt index 833efc5e9..96f2abe1f 100644 --- a/cmd/helm/testdata/output/plugin_list_comp.txt +++ b/cmd/helm/testdata/output/plugin_list_comp.txt @@ -3,5 +3,6 @@ echo echo stuff env env stuff exitwith exitwith code fullenv show env vars +numargs echo num args :4 Completion ended with directive: ShellCompDirectiveNoFileComp diff --git a/cmd/helm/testdata/output/plugin_repeat_comp.txt b/cmd/helm/testdata/output/plugin_repeat_comp.txt index 3fa05f0b3..b3dc44d83 100644 --- a/cmd/helm/testdata/output/plugin_repeat_comp.txt +++ b/cmd/helm/testdata/output/plugin_repeat_comp.txt @@ -2,5 +2,6 @@ echo echo stuff env env stuff exitwith exitwith code fullenv show env vars +numargs echo num args :4 Completion ended with directive: ShellCompDirectiveNoFileComp