diff --git a/cmd/eia-client/cmd/get/get.go b/cmd/eia-client/cmd/get/get.go index 941c16e..5958f2e 100644 --- a/cmd/eia-client/cmd/get/get.go +++ b/cmd/eia-client/cmd/get/get.go @@ -10,4 +10,5 @@ var GetCmd = &cobra.Command{ func init() { GetCmd.AddCommand(GetFacetsCmd) + GetCmd.AddCommand(GetRouteCmd) } diff --git a/cmd/eia-client/cmd/get/get_route.go b/cmd/eia-client/cmd/get/get_route.go new file mode 100644 index 0000000..751363e --- /dev/null +++ b/cmd/eia-client/cmd/get/get_route.go @@ -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 +}