Start get route subcommand

This commit is contained in:
Ryan McGuire 2024-11-26 20:45:29 -05:00
parent 5284353441
commit 5d2d247dde
2 changed files with 52 additions and 0 deletions

View File

@ -10,4 +10,5 @@ var GetCmd = &cobra.Command{
func init() { func init() {
GetCmd.AddCommand(GetFacetsCmd) GetCmd.AddCommand(GetFacetsCmd)
GetCmd.AddCommand(GetRouteCmd)
} }

View File

@ -0,0 +1,51 @@
package get
import (
"strings"
"github.com/spf13/cobra"
"gitea.libretechconsulting.com/50W/eia-api-go/cmd/eia-client/internal/util"
"gitea.libretechconsulting.com/50W/eia-api-go/pkg/eia"
)
var filteredSuffixes = []string{
"Data",
"Facet",
"FacetId",
"Body",
}
var GetRouteCmd = &cobra.Command{
Use: "route",
Aliases: []string{"r"},
Short: "Describe a route",
Args: cobra.ExactArgs(1),
ValidArgsFunction: completeRouteRoutes,
Run: RunGetRouteCmd,
}
func RunGetRouteCmd(cmd *cobra.Command, args []string) {
logger := util.Logger(cmd)
logger.Info().Str("route", args[0]).Msg("getting route description")
}
func completeRouteRoutes(cmd *cobra.Command, args []string, toComplete string) (
[]string, cobra.ShellCompDirective,
) {
routes := eia.GetRoutes()
routeRoutes := make([]string, 0, len(routes))
for _, r := range routes {
for _, suffix := range filteredSuffixes {
if strings.HasSuffix(r, suffix) {
goto next
}
}
routeRoutes = append(routeRoutes, r)
next:
}
// TODO: Filter for toComplete
return routeRoutes, cobra.ShellCompDirectiveNoFileComp
}