package cmd import ( "strconv" "strings" "github.com/spf13/cobra" "golang.org/x/exp/slices" ) func validProjectsFunc(cmd *cobra.Command, args []string, toComplete string) ( []string, cobra.ShellCompDirective) { initProjectCache(cmd, args) return cache.ProjectStrings(toComplete), cobra.ShellCompDirectiveNoFileComp } func validAliasesFunc(cmd *cobra.Command, args []string, toComplete string) ( []string, cobra.ShellCompDirective) { initProjectCache(cmd, args) return cache.AliasStrings(toComplete), cobra.ShellCompDirectiveNoFileComp } func validProjectsOrAliasesFunc(cmd *cobra.Command, args []string, toComplete string) ( []string, cobra.ShellCompDirective) { projectStrings, _ := validAliasesFunc(cmd, args, toComplete) aliasStrings, _ := validProjectsFunc(cmd, args, toComplete) return append(projectStrings, aliasStrings...), cobra.ShellCompDirectiveDefault } func validGitlabRemotesFunc(cmd *cobra.Command, args []string, toComplete string) ( []string, cobra.ShellCompDirective) { remotes := make([]string, 0, len(conf.Gitlabs)) for _, remote := range conf.Gitlabs { if strings.HasPrefix(remote.Host, toComplete) { remotes = append(remotes, remote.Host) } } return remotes, cobra.ShellCompDirectiveNoFileComp } func validLogLevelsFunc(cmd *cobra.Command, args []string, toComplete string) ( []string, cobra.ShellCompDirective) { levels := []string{"info", "warn", "error", "debug"} matchingLevels := make([]string, 0, len(levels)) for _, level := range levels { if strings.HasPrefix(level, toComplete) { matchingLevels = append(matchingLevels, level) } } return matchingLevels, cobra.ShellCompDirectiveNoFileComp } func validProjectIdFunc(cmd *cobra.Command, args []string, toComplete string) ( []string, cobra.ShellCompDirective) { initProjectCache(cmd, args) matchingIds := make([]string, 0, len(cache.Projects)) for _, p := range cache.Projects { idString := strconv.FormatInt(int64(p.ID), 10) if strings.HasPrefix(idString, toComplete) { matchingIds = append(matchingIds, idString) } } return slices.Clip(matchingIds), cobra.ShellCompDirectiveNoFileComp }