From a3f00fde691585ffa2dc4934c6813d69ff0ec284 Mon Sep 17 00:00:00 2001 From: Lennard Eijsackers Date: Mon, 16 Dec 2019 18:14:06 +0100 Subject: [PATCH] fix(helm): Validate number of arguments in install client The 'helm install' command returned confusing error messages if a flag was misspecified (e.g. `helm install name chart --set value foo`). This lead to an error indicating that a name should be specified for the command. Now an explicit check is done on the number of arguments passed, returning a message indicating the invalid arguments (`foo` in the example`). Closes #7225 Signed-off-by: Lennard Eijsackers --- pkg/action/install.go | 4 ++++ pkg/action/install_test.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/action/install.go b/pkg/action/install.go index 89a343a6f..dc5941810 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -555,6 +555,10 @@ func (i *Install) NameAndChart(args []string) (string, string, error) { return nil } + if len(args) > 2 { + return args[0], args[1], errors.Errorf("expected at most two arguments, unexpected arguments: %v", strings.Join(args[2:], ", ")) + } + if len(args) == 2 { return args[0], args[1], flagsNotSet() } diff --git a/pkg/action/install_test.go b/pkg/action/install_test.go index 4637a4b10..d6f1c88cd 100644 --- a/pkg/action/install_test.go +++ b/pkg/action/install_test.go @@ -505,6 +505,14 @@ func TestNameAndChart(t *testing.T) { t.Fatal("expected an error") } is.Equal("must either provide a name or specify --generate-name", err.Error()) + + instAction.NameTemplate = "" + instAction.ReleaseName = "" + _, _, err = instAction.NameAndChart([]string{"foo", chartName, "bar"}) + if err == nil { + t.Fatal("expected an error") + } + is.Equal("expected at most two arguments, unexpected arguments: bar", err.Error()) } func TestNameAndChartGenerateName(t *testing.T) {