From ad9be937751535fa28e5da557a1cc8b7c68886fb Mon Sep 17 00:00:00 2001 From: netbenix Date: Sat, 20 Nov 2021 15:57:22 +0100 Subject: [PATCH] Moved Search related cmds to SearchCommand --- Commands/Handler.go | 39 --------------------------------------- Commands/SearchCommand.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 39 deletions(-) delete mode 100644 Commands/Handler.go diff --git a/Commands/Handler.go b/Commands/Handler.go deleted file mode 100644 index 6033957..0000000 --- a/Commands/Handler.go +++ /dev/null @@ -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 -} diff --git a/Commands/SearchCommand.go b/Commands/SearchCommand.go index 75607fc..3e87da9 100644 --- a/Commands/SearchCommand.go +++ b/Commands/SearchCommand.go @@ -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 } \ No newline at end of file