From 17d9686484b2501531da35eacff66635fdc5a404 Mon Sep 17 00:00:00 2001 From: sinlov Date: Sat, 1 Jul 2023 20:27:22 +0800 Subject: [PATCH] feat: add github.com/gookit/color and show base cli error --- README.md | 3 ++- cmd/main.go | 5 +++-- go.mod | 3 +++ go.sum | 6 ++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6c9618d..d457061 100755 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ We welcome community contributions to this project. Please read [Contributor Guide](.github/CONTRIBUTING_DOC/CONTRIBUTING.md) for more information on how to get started. -## Features +## Features - [ ] more perfect test case coverage - [ ] more perfect benchmark case @@ -48,6 +48,7 @@ Please read [Contributor Guide](.github/CONTRIBUTING_DOC/CONTRIBUTING.md) for mo |:------------------------------------|:--------| | https://github.com/stretchr/testify | v1.8.4 | | https://github.com/urfave/cli/ | v2.23.7 | +| https://github.com/gookit/color | v1.5.3 | | https://github.com/bar-counter/slog | v1.4.0 | ## usage diff --git a/cmd/main.go b/cmd/main.go index 103467d..c2acca5 100755 --- a/cmd/main.go +++ b/cmd/main.go @@ -9,6 +9,7 @@ import ( "github.com/bridgewwater/temp-golang-cli-fast/command/subcommand_new" "github.com/bridgewwater/temp-golang-cli-fast/utils/pkgJson" "github.com/bridgewwater/temp-golang-cli-fast/utils/urfave_cli" + "github.com/gookit/color" "github.com/urfave/cli/v2" os "os" ) @@ -46,10 +47,10 @@ func main() { args := os.Args if len(args) < 2 { - fmt.Printf("please see help as: %s --help\n", app.Name) + fmt.Printf("%s %s --help\n", color.Yellow.Render("please see help as:"), app.Name) os.Exit(2) } if err := app.Run(args); nil != err { - fmt.Printf("run err: %v\n", err) + color.Redf("cli err at %v\n", err) } } diff --git a/go.mod b/go.mod index bd8386f..066ae2f 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.18 require ( github.com/bar-counter/slog v1.4.0 + github.com/gookit/color v1.5.3 github.com/stretchr/testify v1.8.4 github.com/urfave/cli/v2 v2.23.7 ) @@ -13,6 +14,8 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + golang.org/x/sys v0.6.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 396d5a1..20faf3b 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHH github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 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/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE= +github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE= 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 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= @@ -12,8 +14,12 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/urfave/cli/v2 v2.23.7 h1:YHDQ46s3VghFHFf1DdF+Sh7H4RqhcM+t0TmZRJx4oJY= github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=