eia-api-go/cmd/eia-client/internal/util/util_completion.go

24 lines
502 B
Go

package util
import (
"slices"
"strings"
"github.com/spf13/cobra"
"gitea.libretechconsulting.com/50W/eia-api-go/pkg/eia"
)
func CompleteRoutes(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
routes := eia.GetRoutes()
compRoutes := make([]string, 0, len(routes))
for _, r := range routes {
if strings.HasPrefix(r, toComplete) {
compRoutes = append(compRoutes, r)
}
}
return slices.Clip(compRoutes), cobra.ShellCompDirectiveNoFileComp
}