mirror of
https://github.com/helm/helm.git
synced 2026-08-05 07:30:46 +00:00
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>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user