Skip to content

Commit 2fc6f6a

Browse files
committed
Fix flux install command so it returns an error when unexpected arguments are passed
Signed-off-by: Vinícius Garcia <vingarcia00@gmail.com>
1 parent 0fcda45 commit 2fc6f6a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cmd/flux/install.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"path/filepath"
24+
"strings"
2425
"time"
2526

2627
"github.com/manifoldco/promptui"
@@ -52,7 +53,7 @@ If a previous version is installed, then an in-place upgrade will be performed.`
5253
flux install --toleration-keys=node.kubernetes.io/dedicated-to-flux
5354
5455
# Dry-run install
55-
flux install --export | kubectl apply --dry-run=client -f-
56+
flux install --export | kubectl apply --dry-run=client -f-
5657
5758
# Write install manifests to file
5859
flux install --export > flux-system.yaml`,
@@ -114,6 +115,10 @@ func NewInstallFlags() installFlags {
114115
}
115116

116117
func installCmdRun(cmd *cobra.Command, args []string) error {
118+
if len(args) > 0 {
119+
return fmt.Errorf(`flux install received unexpected positional arguments: "%s"`, strings.Join(args, `", "`))
120+
}
121+
117122
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
118123
defer cancel()
119124

cmd/flux/install_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ func TestInstall(t *testing.T) {
3737
args: "install --namespace='@#[]'",
3838
assert: assertError("namespace must be a valid DNS label: \"@#[]\""),
3939
},
40+
{
41+
name: "invalid namespace",
42+
args: "install unexpected pos arg --namespace=example",
43+
assert: assertError("flux install received unexpected positional arguments: \"unexpected\", \"pos\", \"arg\""),
44+
},
4045
}
4146

4247
for _, tt := range tests {

0 commit comments

Comments
 (0)