Moved Search related cmds to SearchCommand
This commit is contained in:
parent
43829e6bcc
commit
ad9be93775
2 changed files with 34 additions and 39 deletions
|
|
@ -1,39 +0,0 @@
|
|||
package Commands
|
||||
|
||||
import (
|
||||
"lpm-cli/Lotus"
|
||||
"lpm-cli/ProtoHandler"
|
||||
proto "lpm-cli/Proto/lpm/go"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
@ -48,3 +50,35 @@ func NewSearchCommand() *cli.Command {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in a new issue