Moved Search related cmds to SearchCommand

This commit is contained in:
netbenix 2021-11-20 15:57:22 +01:00
parent 43829e6bcc
commit ad9be93775
2 changed files with 34 additions and 39 deletions

View file

@ -4,6 +4,8 @@ import (
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
"lpm-cli/Lotus"
"lpm-cli/ProtoHandler"
proto "lpm-cli/proto/lpm/go"
"os"
)
@ -47,4 +49,36 @@ func NewSearchCommand() *cli.Command {
return err
},
}
}
func fetchPackages(platform string, architecture []string, query string, registry Lotus.Registry) *proto.SearchResponse {
var protoWrap ProtoHandler.ProtoWrapper
conn := protoWrap.CreateConnection(registry.Address)
defer conn.Close()
client, ctx, cancel := protoWrap.CreateRegistryClient(conn)
defer cancel()
res, _ := client.Search(ctx, &proto.SearchRequest{Platform: platform, Architecture: architecture, Query: query})
return res
}
func SearchPackages(platform string, architecture []string, query string) []ProtoHandler.Package {
var packages []ProtoHandler.Package
var protoWrap ProtoHandler.ProtoWrapper
registries := Lotus.GetRegistries()
for _, reg := range registries {
res := fetchPackages(platform, architecture, query, reg)
if res != nil{
for _, pkg := range protoWrap.ParsePackages(res, reg){
packages = append(packages, pkg)
}
}
}
return packages
}