package list import ( "context" "fmt" "time" "edge-infra.dev/pkg/edge/edgecli" "edge-infra.dev/pkg/edge/edgecli/constructors" "edge-infra.dev/pkg/edge/edgecli/flagutil" "edge-infra.dev/pkg/lib/cli/command" "edge-infra.dev/pkg/lib/cli/rags" ) func NewCmd(cfg *edgecli.Config) *command.Command { var cmd *command.Command flagsets := flagutil.GetConnectionFlags(cfg) var storeName, bannerName string cmd = &command.Command{ ShortUsage: "edge activationcode list", ShortHelp: "List a clusters' terminal activation codes", Flags: append( flagsets, &rags.Rag{ Name: flagutil.StoreFlag, Usage: "Name of the Store", Value: &rags.String{Var: &storeName}, Required: true, }, &rags.Rag{ Name: flagutil.BannerFlag, Usage: "Banner name", Value: &rags.String{Var: &bannerName}, Required: true, }, ), Exec: func(_ context.Context, _ []string) error { if err := flagutil.ValidateRequiredFlags(cmd.Rags); err != nil { return err } registrar, err := constructors.BuildRegistrar(cmd.Rags) if err != nil { return err } fmt.Println("flags validated") reqCtx, cancelReq := context.WithTimeout(context.Background(), time.Duration(30)*time.Second) defer cancelReq() cluster, err := registrar.GetCluster(reqCtx, storeName, bannerName) if err != nil { fmt.Println("an error occurred whilst modifying the cluster network service") return err } terminals, err := registrar.GetTerminals(reqCtx, cluster.ClusterEdgeID) if err != nil { return err } fmt.Println("-----------------------------------") fmt.Println("List of Cluster's Activation Codes") fmt.Println("-----------------------------------") for _, terminal := range terminals { if terminal.ActivationCode == nil || *terminal.ActivationCode == "" { fmt.Printf("%s: \n", terminal.Hostname) continue } fmt.Printf("%s: %s\n", terminal.Hostname, *terminal.ActivationCode) } return nil }, } return cmd }