Skip to content

Commit

Permalink
use slice.FindAll() instead of slices.Filter()
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Sep 26, 2024
1 parent eb0c83b commit 4247085
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pkg/utils/completion/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})

Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/completion/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/completion/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})

Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/completion/config-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/completion/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
})

Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/completion/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
})

Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/completion/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
})

Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/completion/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})

Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/completion/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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_")
})

Expand Down

0 comments on commit 4247085

Please sign in to comment.