This repository has been archived on 2026-03-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
lotus-package-manager/Commands/SearchCommand.go
2021-11-06 22:40:56 +01:00

59 lines
1.3 KiB
Go

package Commands
import (
"context"
"fmt"
"github.com/urfave/cli/v2"
"google.golang.org/grpc"
"lpm-cli/Lotus"
proto "lpm-cli/Proto/lpm/go"
"time"
)
func NewSearchCommand() *cli.Command {
logger := Lotus.Logger("searchCommand")
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.Fatal(err)
}
defer conn.Close()
lrc := proto.NewLpmRegistryClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, connErr := lrc.Search(ctx, &proto.SearchRequest {Platform: "noot", Architecture: nil, Query: "Schnitzel"})
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
},
}
}