From 11163a3ec68d113acf0b7bac8ca00c65ee16c4c3 Mon Sep 17 00:00:00 2001 From: Suleiman Dibirov Date: Wed, 10 Jul 2024 18:16:36 +0300 Subject: [PATCH] fix(flags): Replace slices.Contains with sliceContains custom func --- cmd/kubens/flags.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/kubens/flags.go b/cmd/kubens/flags.go index 030889c..0ad5ae0 100644 --- a/cmd/kubens/flags.go +++ b/cmd/kubens/flags.go @@ -18,7 +18,6 @@ import ( "fmt" "io" "os" - "slices" "strings" "github.com/ahmetb/kubectx/internal/cmdutil" @@ -58,10 +57,10 @@ func parseArgs(argv []string) Op { } else if n == 2 { // {namespace} -f|--force name := argv[0] - force := slices.Contains([]string{"-f", "--force"}, argv[1]) + force := sliceContains([]string{"-f", "--force"}, argv[1]) if !force { - if !slices.Contains([]string{"-f", "--force"}, argv[0]) { + if !sliceContains([]string{"-f", "--force"}, argv[0]) { return UnsupportedOp{Err: fmt.Errorf("unsupported arguments %q", argv)} } @@ -82,3 +81,14 @@ func getSwitchOp(v string, force bool) Op { } return SwitchOp{Target: v, Force: force} } + +// sliceContains returns true if slice contains item. +// todo replace with slices.Contains after upgrading to go 1.21 +func sliceContains(slice []string, item string) bool { + for _, v := range slice { + if v == item { + return true + } + } + return false +}