Updated logging
This commit is contained in:
parent
8f60c9ce7c
commit
ff9e4b3e3a
8 changed files with 106 additions and 30 deletions
|
|
@ -1,12 +1,15 @@
|
||||||
package Commands
|
package Commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"lpm-cli/Tools"
|
"lpm-cli/Lotus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ListCommand() *cli.Command{
|
func NewListCommand() *cli.Command{
|
||||||
|
|
||||||
|
logger := Lotus.CreateLogger("listCommand", logrus.WarnLevel)
|
||||||
|
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "Lists all packages",
|
Usage: "Lists all packages",
|
||||||
|
|
@ -18,8 +21,7 @@ func ListCommand() *cli.Command{
|
||||||
},
|
},
|
||||||
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
|
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("[ERROR] %s", err.Error())
|
logger.Fatal(err)
|
||||||
Tools.ErrorLogger.Fatal(err)
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
package Commands
|
package Commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"lpm-cli/Tools"
|
"lpm-cli/Lotus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PullCommand() *cli.Command{
|
func NewPullCommand() *cli.Command{
|
||||||
|
|
||||||
|
logger := Lotus.CreateLogger("pullCommand", logrus.WarnLevel)
|
||||||
|
|
||||||
return &cli.Command {
|
return &cli.Command {
|
||||||
Name: "pull",
|
Name: "pull",
|
||||||
Usage: "Pull a package",
|
Usage: "Pull a package",
|
||||||
|
|
@ -18,8 +21,7 @@ func PullCommand() *cli.Command{
|
||||||
},
|
},
|
||||||
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
|
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("[ERROR] %s", err.Error())
|
logger.Fatal(err)
|
||||||
Tools.ErrorLogger.Fatal(err)
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
package Commands
|
package Commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"lpm-cli/Tools"
|
"lpm-cli/Lotus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PushCommand() *cli.Command {
|
func NewPushCommand() *cli.Command {
|
||||||
|
|
||||||
|
logger := Lotus.CreateLogger("pushCommand", logrus.WarnLevel)
|
||||||
|
|
||||||
return &cli.Command {
|
return &cli.Command {
|
||||||
Name: "push",
|
Name: "push",
|
||||||
Usage: "Push a package",
|
Usage: "Push a package",
|
||||||
|
|
@ -18,8 +21,7 @@ func PushCommand() *cli.Command {
|
||||||
},
|
},
|
||||||
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
|
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
|
||||||
if err != nil{
|
if err != nil{
|
||||||
fmt.Printf("[ERROR] %s", err.Error())
|
logger.Fatal(err)
|
||||||
Tools.ErrorLogger.Fatal(err)
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,60 @@
|
||||||
package Commands
|
package Commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/urfave/cli/v2"
|
"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 {
|
return &cli.Command {
|
||||||
Name: "search",
|
Name: "search",
|
||||||
Usage: "Seaches a packages",
|
Usage: "Seaches a packages",
|
||||||
Description: "Sends a search request to the default registry server, or to a user-defined registry server",
|
Description: "Sends a search request to the default registry server, or to a user-defined registry server",
|
||||||
HelpName: "search",
|
HelpName: "search",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
//Do Stuff
|
|
||||||
|
//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
|
return nil
|
||||||
},
|
},
|
||||||
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
|
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
|
||||||
if err != nil{
|
if err != nil{
|
||||||
fmt.Printf("[ERROR]%s", err.Error())
|
logger.Fatal(err)
|
||||||
Tools.ErrorLogger.Fatal(err)
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
|
|
||||||
23
Lotus/LotusProto.go
Normal file
23
Lotus/LotusProto.go
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
package Lotus
|
||||||
|
|
||||||
|
import (
|
||||||
|
proto "lpm-cli/Proto/lpm/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LotusProtoHandler struct {}
|
||||||
|
|
||||||
|
var (
|
||||||
|
LotusProto *LotusProtoHandler
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func (lph* LotusProtoHandler) GetPackageMetasFromRegistry(registry string) []proto.PackageMetadata{
|
||||||
|
|
||||||
|
//var addr = flag.String("addr", "localhost:50051", "connection addr")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
1
go.mod
1
go.mod
|
|
@ -4,6 +4,7 @@ go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/golang/protobuf v1.5.2
|
github.com/golang/protobuf v1.5.2
|
||||||
|
github.com/sirupsen/logrus v1.8.1
|
||||||
github.com/urfave/cli/v2 v2.3.0
|
github.com/urfave/cli/v2 v2.3.0
|
||||||
google.golang.org/grpc v1.42.0
|
google.golang.org/grpc v1.42.0
|
||||||
google.golang.org/protobuf v1.27.1
|
google.golang.org/protobuf v1.27.1
|
||||||
|
|
|
||||||
8
go.sum
8
go.sum
|
|
@ -14,6 +14,8 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||||
|
|
@ -54,8 +56,12 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
|
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||||
|
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||||
|
|
@ -83,6 +89,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
|
||||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
|
|
@ -125,6 +132,7 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
|
|
||||||
19
main.go
19
main.go
|
|
@ -4,29 +4,32 @@ import (
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"lpm-cli/Commands"
|
"lpm-cli/Commands"
|
||||||
"lpm-cli/Informations"
|
"lpm-cli/Informations"
|
||||||
. "lpm-cli/Logging"
|
"github.com/sirupsen/logrus"
|
||||||
|
"lpm-cli/Lotus"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
Logger.Init()
|
|
||||||
|
|
||||||
Logger.Info("Lotus-PM was executed")
|
logger := Lotus.CreateLogger("mainThread", logrus.InfoLevel)
|
||||||
|
|
||||||
app := &cli.App {
|
app := &cli.App {
|
||||||
Name: "lotus-pm",
|
Name: "lotus-pm",
|
||||||
Usage: "Lotus Package Manager",
|
Usage: "Lotus Package Manager",
|
||||||
Authors: Informations.GetAuthors(),
|
Authors: Informations.GetAuthors(),
|
||||||
Copyright: "(c) 2021 LPM-Group",
|
Copyright: "(c) 2021 LPM-Group",
|
||||||
Commands: []*cli.Command {
|
Commands: []*cli.Command {
|
||||||
Commands.PushCommand(),
|
Commands.NewPushCommand(),
|
||||||
Commands.PullCommand(),
|
Commands.NewPullCommand(),
|
||||||
Commands.SearchCommand(),
|
Commands.NewSearchCommand(),
|
||||||
Commands.ListCommand(),
|
Commands.NewListCommand(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
err := app.Run(os.Args)
|
err := app.Run(os.Args)
|
||||||
ErrorHandler.HandleFatal(err)
|
if err != nil{
|
||||||
|
logger.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in a new issue