Start get route subcommand
This commit is contained in:
parent
5284353441
commit
5d2d247dde
@ -10,4 +10,5 @@ var GetCmd = &cobra.Command{
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
GetCmd.AddCommand(GetFacetsCmd)
|
GetCmd.AddCommand(GetFacetsCmd)
|
||||||
|
GetCmd.AddCommand(GetRouteCmd)
|
||||||
}
|
}
|
||||||
|
51
cmd/eia-client/cmd/get/get_route.go
Normal file
51
cmd/eia-client/cmd/get/get_route.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user