Updated logging

This commit is contained in:
netbenix 2021-11-06 20:55:55 +01:00
parent 8f60c9ce7c
commit ff9e4b3e3a
8 changed files with 106 additions and 30 deletions

View file

@ -1,25 +1,60 @@
package Commands
import (
"context"
"fmt"
"github.com/urfave/cli/v2"
"lpm-cli/Tools"
"google.golang.org/grpc"
"github.com/sirupsen/logrus"
"lpm-cli/Lotus"
proto "lpm-cli/Proto/lpm/go"
"time"
)
func SearchCommand() *cli.Command{
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{
//Do Stuff
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 {
fmt.Printf("[ERROR]%s", err.Error())
Tools.ErrorLogger.Fatal(err)
if err != nil{
logger.Fatal(err)
}
return err
},