diff --git a/pkg/describe/describe.go b/pkg/describe/describe.go index b6014f9e5..bbc9d2a4c 100644 --- a/pkg/describe/describe.go +++ b/pkg/describe/describe.go @@ -81,7 +81,6 @@ import ( "k8s.io/kubectl/pkg/util/qos" "k8s.io/kubectl/pkg/util/rbac" resourcehelper "k8s.io/kubectl/pkg/util/resource" - "k8s.io/kubectl/pkg/util/slice" storageutil "k8s.io/kubectl/pkg/util/storage" ) @@ -312,7 +311,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte switch typedValue := value.(type) { case map[string]interface{}: skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field) - if slice.Contains[string](skip, skipExpr, nil) { + if slices.Contains(skip, skipExpr) { continue } w.Write(level, "%s:\n", smartLabelFor(field)) @@ -320,7 +319,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte case []interface{}: skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field) - if slice.Contains[string](skip, skipExpr, nil) { + if slices.Contains(skip, skipExpr) { continue } w.Write(level, "%s:\n", smartLabelFor(field)) @@ -335,7 +334,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte default: skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field) - if slice.Contains[string](skip, skipExpr, nil) { + if slices.Contains(skip, skipExpr) { continue } w.Write(level, "%s:\t%v\n", smartLabelFor(field), typedValue) @@ -383,7 +382,7 @@ func smartLabelFor(field string) string { continue } - if slice.Contains(commonAcronyms, strings.ToUpper(part), nil) { + if slices.Contains(commonAcronyms, strings.ToUpper(part)) { part = strings.ToUpper(part) } else if strings.ToLower(part) == part { part = cases.Title(language.English).String(part) diff --git a/pkg/util/slice/slice.go b/pkg/util/slice/slice.go index c65756da8..69e968931 100644 --- a/pkg/util/slice/slice.go +++ b/pkg/util/slice/slice.go @@ -18,36 +18,35 @@ package slice import "slices" -// SortInts64 sorts []int64 in increasing order +// SortInts64 sorts []int64 in increasing order. +// +// Deprecated: Use slices.Sort instead. +// +//go:fix inline func SortInts64(a []int64) { slices.Sort(a) } // Contains checks if a given slice of type T contains the provided item. // If a modifier func is provided, it is called with the slice item before the comparation. +// +// Deprecated: Use slices.Contains or slices.ContainsFunc instead. func Contains[T comparable](slice []T, s T, modifier func(s T) T) bool { - for _, item := range slice { - if item == s { - return true - } - if modifier != nil && modifier(item) == s { - return true - } + if slices.Contains(slice, s) { + return true + } + if modifier != nil { + return slices.ContainsFunc(slice, func(item T) bool { return modifier(item) == s }) } return false } // ContainsString checks if a given slice of strings contains the provided string. // If a modifier func is provided, it is called with the slice item before the comparation. -// Deprecated: Use Contains[T] instead +// +// Deprecated: Use slices.Contains or slices.ContainsFunc instead. +// +//go:fix inline func ContainsString(slice []string, s string, modifier func(s string) string) bool { - for _, item := range slice { - if item == s { - return true - } - if modifier != nil && modifier(item) == s { - return true - } - } - return false + return Contains(slice, s, modifier) } // ToSet returns a single slice containing the unique values from one or more slices. The order of the items in the