79 lines
2.5 KiB
Go
79 lines
2.5 KiB
Go
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 projectCache.ProjectStrings(toComplete), cobra.ShellCompDirectiveNoFileComp
|
|
}
|
|
|
|
func validAliasesFunc(cmd *cobra.Command, args []string, toComplete string) (
|
|
[]string, cobra.ShellCompDirective) {
|
|
initProjectCache(cmd, args)
|
|
return projectCache.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 validRemotesFunc(cmd *cobra.Command, args []string, toComplete string) (
|
|
[]string, cobra.ShellCompDirective) {
|
|
var ttlRemotes int
|
|
ttlRemotes += len(conf.Gitlabs)
|
|
ttlRemotes += len(conf.Giteas)
|
|
remotes := make([]string, 0, ttlRemotes)
|
|
for _, remote := range conf.Gitlabs {
|
|
if strings.HasPrefix(remote.Host, toComplete) {
|
|
remotes = append(remotes, remote.Host)
|
|
}
|
|
}
|
|
return remotes, cobra.ShellCompDirectiveNoFileComp
|
|
}
|
|
|
|
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(projectCache.Projects))
|
|
for _, p := range projectCache.Projects {
|
|
idString := strconv.FormatInt(int64(p.ID), 10)
|
|
if strings.HasPrefix(idString, toComplete) {
|
|
matchingIds = append(matchingIds, idString)
|
|
}
|
|
}
|
|
return slices.Clip(matchingIds), cobra.ShellCompDirectiveNoFileComp
|
|
}
|