From 1d3e349d92855b16baf9b0c26c2fc75dc7b95159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Tue, 14 Nov 2023 22:31:01 -0300 Subject: [PATCH] Fix flux install command so it returns an error when unexpected arguments are passed --- cmd/flux/install.go | 7 ++++++- cmd/flux/install_test.go | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/flux/install.go b/cmd/flux/install.go index 795cc1aad7..04abcf74bc 100644 --- a/cmd/flux/install.go +++ b/cmd/flux/install.go @@ -21,6 +21,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "time" "github.com/manifoldco/promptui" @@ -52,7 +53,7 @@ If a previous version is installed, then an in-place upgrade will be performed.` flux install --toleration-keys=node.kubernetes.io/dedicated-to-flux # Dry-run install - flux install --export | kubectl apply --dry-run=client -f- + flux install --export | kubectl apply --dry-run=client -f- # Write install manifests to file flux install --export > flux-system.yaml`, @@ -114,6 +115,10 @@ func NewInstallFlags() installFlags { } func installCmdRun(cmd *cobra.Command, args []string) error { + if len(args) > 0 { + return fmt.Errorf(`flux install received unexpected positional arguments: "%s"`, strings.Join(args, `", "`)) + } + ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() diff --git a/cmd/flux/install_test.go b/cmd/flux/install_test.go index f10f7d62a2..6c00490727 100644 --- a/cmd/flux/install_test.go +++ b/cmd/flux/install_test.go @@ -37,6 +37,11 @@ func TestInstall(t *testing.T) { args: "install --namespace='@#[]'", assert: assertError("namespace must be a valid DNS label: \"@#[]\""), }, + { + name: "invalid namespace", + args: "install unexpected pos arg --namespace=example", + assert: assertError("flux install received unexpected positional arguments: \"unexpected\", \"pos\", \"arg\""), + }, } for _, tt := range tests {