feat: log to logrus
This commit is contained in:
parent
1e781d1277
commit
b220cab2ae
2
go.mod
2
go.mod
@ -4,7 +4,9 @@ go 1.20
|
||||
|
||||
require (
|
||||
github.com/google/go-github/v53 v53.0.0
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/spf13/cobra v1.7.0
|
||||
gitter.top/coco/lormatter v0.0.0-20230409145644-f9cb43f740dc
|
||||
golang.org/x/mod v0.10.0
|
||||
)
|
||||
|
||||
|
20
go.sum
20
go.sum
@ -1,13 +1,12 @@
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230528122434-6f98819771a1 h1:JMDGhoQvXNTqH6Y3MC0IUw6tcZvaUdujNqzK2HYWZc8=
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230528122434-6f98819771a1/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
|
||||
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
|
||||
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
|
||||
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
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/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
@ -21,12 +20,21 @@ github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
gitter.top/coco/lormatter v0.0.0-20230409145644-f9cb43f740dc h1:B0bnfX8Y/dETV+zdcZNCwD/L+DLZN2wSf9szo/fxNCw=
|
||||
gitter.top/coco/lormatter v0.0.0-20230409145644-f9cb43f740dc/go.mod h1:vyfU6MQ56tkoFKSzEzhYSwXjgZHMcu3AViHC3hIyO7I=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
@ -53,8 +61,8 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@ -87,4 +95,6 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
21
gomod.go
21
gomod.go
@ -3,6 +3,7 @@ package gomod
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
@ -25,12 +26,12 @@ func command(url string) error {
|
||||
func AllModUpgrade() {
|
||||
modFileData, err := os.ReadFile("go.mod")
|
||||
if err != nil {
|
||||
fmt.Printf("read go.mod file failed: %v\n", err)
|
||||
logrus.Errorf("read go.mod file failed: %v", err)
|
||||
return
|
||||
}
|
||||
modFile, err := modfile.Parse("go.mod", modFileData, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("parse go.mod file failed: %v\n", err)
|
||||
logrus.Errorf("parse go.mod file failed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -38,12 +39,12 @@ func AllModUpgrade() {
|
||||
if mod.Indirect {
|
||||
continue
|
||||
}
|
||||
fmt.Printf("go get -u %s\n", mod.Mod.String())
|
||||
logrus.Infof("go get -u %s", mod.Mod.String())
|
||||
if err := command(mod.Mod.String()); err != nil {
|
||||
fmt.Printf("upgrade %s failed: %v\n", mod.Mod.String(), err)
|
||||
logrus.Errorf("upgrade %s failed: %v", mod.Mod.String(), err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("upgrade %s success\n", mod.Mod.String())
|
||||
logrus.Infof("upgrade %s success", mod.Mod.String())
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,19 +57,19 @@ func SingleModUpgrade(url string) {
|
||||
}
|
||||
}
|
||||
if err := command(version); err != nil {
|
||||
fmt.Printf("upgrade %s failed: %v\n", version, err)
|
||||
logrus.Errorf("upgrade %s failed: %v", version, err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("upgrade %s success\n", version)
|
||||
logrus.Infof("upgrade %s success", version)
|
||||
}
|
||||
|
||||
func parseUrl(url string) (owner, repo string) {
|
||||
res := githubRegexp.FindAllStringSubmatch(url, -1)
|
||||
if len(res) != 1 {
|
||||
panic(fmt.Sprintf("%s url no match github url rule: %s", url, githubRegexp.String()))
|
||||
logrus.Panicf(fmt.Sprintf("%s url no match github url rule: %s", url, githubRegexp.String()))
|
||||
}
|
||||
if len(res[0]) != 3 {
|
||||
panic(fmt.Sprintf("%s url no match github url rule: %s", url, githubRegexp.String()))
|
||||
logrus.Panicf(fmt.Sprintf("%s url no match github url rule: %s", url, githubRegexp.String()))
|
||||
}
|
||||
return res[0][1], res[0][2]
|
||||
}
|
||||
@ -82,7 +83,7 @@ func getCommitID(url string) (string, error) {
|
||||
PerPage: 1,
|
||||
})
|
||||
if len(tags) == 0 && err != nil {
|
||||
fmt.Printf("get tag info failed: %v, start get commit id", err)
|
||||
logrus.Warnf("get tag info failed: %v, start get commit id", err)
|
||||
}
|
||||
commits, _, err := client.Repositories.ListCommits(ctx, owner, repo, &github.CommitsListOptions{
|
||||
ListOptions: github.ListOptions{
|
||||
|
@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"gitter.top/coco/lormatter"
|
||||
|
||||
"gitter.top/apps/gomod"
|
||||
)
|
||||
@ -11,6 +11,10 @@ import (
|
||||
var mod *cobra.Command
|
||||
|
||||
func init() {
|
||||
formatter := &lormatter.Formatter{}
|
||||
logrus.SetFormatter(formatter)
|
||||
logrus.SetReportCaller(true)
|
||||
|
||||
mod = &cobra.Command{
|
||||
Use: "gomod",
|
||||
Short: "go mod manager",
|
||||
@ -35,7 +39,7 @@ func single() *cobra.Command {
|
||||
Short: "upgrade go mod from url",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) == 0 {
|
||||
fmt.Println("url empty")
|
||||
logrus.Error("url empty, skip upgrade")
|
||||
return
|
||||
}
|
||||
for _, url := range args {
|
||||
@ -47,6 +51,6 @@ func single() *cobra.Command {
|
||||
|
||||
func main() {
|
||||
if err := mod.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
logrus.Errorf("execute command failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user