From 4247085e06672059a53b664e9673edc3b688fcce Mon Sep 17 00:00:00 2001 From: Richard87 Date: Thu, 26 Sep 2024 11:02:50 +0200 Subject: [PATCH] use slice.FindAll() instead of slices.Filter() --- pkg/utils/completion/alias.go | 4 ++-- pkg/utils/completion/application.go | 3 +-- pkg/utils/completion/component.go | 3 +-- pkg/utils/completion/config-context.go | 4 ++-- pkg/utils/completion/deployments.go | 3 +-- pkg/utils/completion/environment.go | 3 +-- pkg/utils/completion/job.go | 3 +-- pkg/utils/completion/secrets.go | 3 +-- pkg/utils/completion/variable.go | 4 ++-- 9 files changed, 12 insertions(+), 18 deletions(-) diff --git a/pkg/utils/completion/alias.go b/pkg/utils/completion/alias.go index 8fe268d..401b683 100644 --- a/pkg/utils/completion/alias.go +++ b/pkg/utils/completion/alias.go @@ -8,8 +8,8 @@ import ( "github.com/equinor/radix-cli/pkg/config" "github.com/equinor/radix-cli/pkg/flagnames" "github.com/equinor/radix-common/utils/pointers" + "github.com/equinor/radix-common/utils/slice" "github.com/spf13/cobra" - "k8s.io/utils/strings/slices" ) func AliasCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) { @@ -47,7 +47,7 @@ func AliasCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]strin } } - filteredNames := slices.Filter(nil, names, func(name string) bool { + filteredNames := slice.FindAll(names, func(name string) bool { return strings.HasPrefix(name, toComplete) }) diff --git a/pkg/utils/completion/application.go b/pkg/utils/completion/application.go index c57941f..1c443a2 100644 --- a/pkg/utils/completion/application.go +++ b/pkg/utils/completion/application.go @@ -9,7 +9,6 @@ import ( "github.com/equinor/radix-cli/pkg/config" "github.com/equinor/radix-common/utils/slice" "github.com/spf13/cobra" - "k8s.io/utils/strings/slices" ) const knownApps = "known_apps" @@ -32,7 +31,7 @@ func ApplicationCompletion(cmd *cobra.Command, _ []string, toComplete string) ([ appNames := slice.Map(resp.Payload, func(app *models.ApplicationSummary) string { return app.Name }) - applications := slices.Filter(nil, appNames, func(appName string) bool { + applications := slice.FindAll(appNames, func(appName string) bool { return strings.HasPrefix(appName, toComplete) }) config.SetCache(knownApps, applications, config.DefaultCacheDuration) diff --git a/pkg/utils/completion/component.go b/pkg/utils/completion/component.go index 2ff6567..db80bf7 100644 --- a/pkg/utils/completion/component.go +++ b/pkg/utils/completion/component.go @@ -11,7 +11,6 @@ import ( "github.com/equinor/radix-common/utils/pointers" "github.com/equinor/radix-common/utils/slice" "github.com/spf13/cobra" - "k8s.io/utils/strings/slices" ) func ComponentCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) { @@ -40,7 +39,7 @@ func ComponentCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]s return pointers.Val(component.Name) }) - filteredNames := slices.Filter(nil, names, func(appName string) bool { + filteredNames := slice.FindAll(names, func(appName string) bool { return strings.HasPrefix(appName, toComplete) }) diff --git a/pkg/utils/completion/config-context.go b/pkg/utils/completion/config-context.go index 6745ddf..a9bfea7 100644 --- a/pkg/utils/completion/config-context.go +++ b/pkg/utils/completion/config-context.go @@ -4,12 +4,12 @@ import ( "strings" "github.com/equinor/radix-cli/pkg/config" + "github.com/equinor/radix-common/utils/slice" "github.com/spf13/cobra" - "k8s.io/utils/strings/slices" ) func ConfigContext(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) { - contexts := slices.Filter(nil, config.ValidContexts, func(appName string) bool { + contexts := slice.FindAll(config.ValidContexts, func(appName string) bool { return strings.HasPrefix(appName, toComplete) }) return contexts, cobra.ShellCompDirectiveNoFileComp diff --git a/pkg/utils/completion/deployments.go b/pkg/utils/completion/deployments.go index 5343266..c3b4e2f 100644 --- a/pkg/utils/completion/deployments.go +++ b/pkg/utils/completion/deployments.go @@ -13,7 +13,6 @@ import ( "github.com/equinor/radix-common/utils/pointers" "github.com/equinor/radix-common/utils/slice" "github.com/spf13/cobra" - "k8s.io/utils/strings/slices" ) func CreateDeploymentCompletion(environmentFlagName string, envRequired bool) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { @@ -39,7 +38,7 @@ func CreateDeploymentCompletion(environmentFlagName string, envRequired bool) fu names = getEnvironmentDeployments(appName, envName, apiClient) } - filteredNames := slices.Filter(nil, names, func(name string) bool { + filteredNames := slice.FindAll(names, func(name string) bool { return strings.HasPrefix(name, toComplete) }) diff --git a/pkg/utils/completion/environment.go b/pkg/utils/completion/environment.go index c217d44..3e13f12 100644 --- a/pkg/utils/completion/environment.go +++ b/pkg/utils/completion/environment.go @@ -10,7 +10,6 @@ import ( "github.com/equinor/radix-cli/pkg/flagnames" "github.com/equinor/radix-common/utils/slice" "github.com/spf13/cobra" - "k8s.io/utils/strings/slices" ) func EnvironmentCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) { @@ -34,7 +33,7 @@ func EnvironmentCompletion(cmd *cobra.Command, _ []string, toComplete string) ([ names := slice.Map(resp.Payload.Environments, func(item *models.EnvironmentSummary) string { return item.Name }) - filteredNames := slices.Filter(nil, names, func(name string) bool { + filteredNames := slice.FindAll(names, func(name string) bool { return strings.HasPrefix(name, toComplete) }) diff --git a/pkg/utils/completion/job.go b/pkg/utils/completion/job.go index cbd6f73..ad0a177 100644 --- a/pkg/utils/completion/job.go +++ b/pkg/utils/completion/job.go @@ -10,7 +10,6 @@ import ( "github.com/equinor/radix-cli/pkg/flagnames" "github.com/equinor/radix-common/utils/slice" "github.com/spf13/cobra" - "k8s.io/utils/strings/slices" ) func JobCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) { @@ -34,7 +33,7 @@ func JobCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]string, return component.Name }) - filteredNames := slices.Filter(nil, names, func(appName string) bool { + filteredNames := slice.FindAll(names, func(appName string) bool { return strings.HasPrefix(appName, toComplete) }) diff --git a/pkg/utils/completion/secrets.go b/pkg/utils/completion/secrets.go index ec6b3ae..68cd608 100644 --- a/pkg/utils/completion/secrets.go +++ b/pkg/utils/completion/secrets.go @@ -11,7 +11,6 @@ import ( "github.com/equinor/radix-common/utils/pointers" "github.com/equinor/radix-common/utils/slice" "github.com/spf13/cobra" - "k8s.io/utils/strings/slices" ) func SecretCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) { @@ -42,7 +41,7 @@ func SecretCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]stri return pointers.Val(item.Name) }) - filteredNames := slices.Filter(nil, names, func(name string) bool { + filteredNames := slice.FindAll(names, func(name string) bool { return strings.HasPrefix(name, toComplete) }) diff --git a/pkg/utils/completion/variable.go b/pkg/utils/completion/variable.go index 0e69add..13ce168 100644 --- a/pkg/utils/completion/variable.go +++ b/pkg/utils/completion/variable.go @@ -7,8 +7,8 @@ import ( "github.com/equinor/radix-cli/pkg/client" "github.com/equinor/radix-cli/pkg/config" "github.com/equinor/radix-cli/pkg/flagnames" + "github.com/equinor/radix-common/utils/slice" "github.com/spf13/cobra" - "k8s.io/utils/strings/slices" ) func VariableCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) { @@ -44,7 +44,7 @@ func VariableCompletion(cmd *cobra.Command, _ []string, toComplete string) ([]st } } - filteredNames := slices.Filter(nil, names, func(name string) bool { + filteredNames := slice.FindAll(names, func(name string) bool { return strings.HasPrefix(name, toComplete) && !strings.HasPrefix(name, "RADIX_") })