Skip to content

Commit

Permalink
fix(flags): Replace slices.Contains with sliceContains custom func
Browse files Browse the repository at this point in the history
  • Loading branch information
idsulik committed Jul 10, 2024
1 parent b5daf2c commit 11163a3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/kubens/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"io"
"os"
"slices"
"strings"

"github.com/ahmetb/kubectx/internal/cmdutil"
Expand Down Expand Up @@ -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)}
}

Expand All @@ -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
}

0 comments on commit 11163a3

Please sign in to comment.