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 <lennardeijsackers92@gmail.com>
pull/7240/head
Lennard Eijsackers 5 years ago
parent 0fd76b2a2b
commit a3f00fde69

@ -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()
}

@ -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) {

Loading…
Cancel
Save