package Commands import ( "context" "fmt" "github.com/urfave/cli/v2" "google.golang.org/grpc" "github.com/sirupsen/logrus" "lpm-cli/Lotus" proto "lpm-cli/Proto/lpm/go" "time" ) func NewSearchCommand() *cli.Command { logger := Lotus.CreateLogger("searchCommand", logrus.WarnLevel) return &cli.Command { Name: "search", Usage: "Seaches a packages", Description: "Sends a search request to the default registry server, or to a user-defined registry server", HelpName: "search", Action: func(c *cli.Context) error { //TODO Remove Hardcoded addr conn, err := grpc.Dial("faf-notebook2:9090", grpc.WithInsecure()) if err != nil{ logger.Error(err) } defer conn.Close() lrc := proto.NewLpmRegistryClient(conn) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() start := time.Now() r, connErr := lrc.Search(ctx, &proto.SearchRequest {Platform: "noot", Architecture: nil, Query: "Schnitzel"}) fmt.Printf("%d", time.Since(start).Milliseconds()) if connErr != nil { logger.Fatal(connErr) } packages := r.GetPackages() fmt.Printf("Packages: ") for _, pkg := range packages { fmt.Printf("%s\t\t\t\t\t%s\t\t\t\t\t%s\n", pkg.GetArchitecture(), pkg.GetPublisher(), pkg.GetVersion()) } return nil }, OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error { if err != nil{ logger.Fatal(err) } return err }, } }