From 51e6c01c5abc533a79f34f4f9ecb1cad00865308 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Wed, 19 Jun 2024 14:16:10 -0600 Subject: [PATCH 1/4] remove statuscode.RenderHelp --- internal/commands/help.go | 9 ++++++--- pkg/errors/handler.go | 6 +----- pkg/statuscode/statuscode.go | 2 -- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/internal/commands/help.go b/internal/commands/help.go index 91365f4..8dec5b8 100644 --- a/internal/commands/help.go +++ b/internal/commands/help.go @@ -53,9 +53,9 @@ By default, and unless ﹅` + env.NoColor + `﹅ is set, ﹅@chinampa@ help﹅ w if len(args) > 0 && c != nil && c.Name() != args[len(args)-1] { c, topicArgs, err := c.Root().Find(args) if err == nil && c != nil && len(topicArgs) == 0 { - // exact command help + // user requestd command help with flag command cobra.CheckErr(c.Help()) - os.Exit(statuscode.RenderHelp) + os.Exit(statuscode.Ok) return } @@ -74,9 +74,12 @@ By default, and unless ﹅` + env.NoColor + `﹅ is set, ﹅@chinampa@ help﹅ w os.Exit(statuscode.NotFound) } + // top-level help with no arguments called + // write to stdout + c.SetOut(os.Stdout) c.InitDefaultHelpFlag() // make possible 'help' flag to be shown cobra.CheckErr(c.Help()) - os.Exit(statuscode.RenderHelp) + os.Exit(statuscode.Ok) }, } diff --git a/pkg/errors/handler.go b/pkg/errors/handler.go index d63a15e..691df8e 100644 --- a/pkg/errors/handler.go +++ b/pkg/errors/handler.go @@ -25,12 +25,8 @@ func showHelp(cmd *cobra.Command) { // HandleCobraExit is called when a command errors out or was not found. func HandleCobraExit(cmd *cobra.Command, err error) error { if err == nil { - ok, err := cmd.PersistentFlags().GetBool(_c.HelpCommandName) - if cmd.Name() == _c.HelpCommandName || err == nil && ok { - os.Exit(statuscode.RenderHelp) - } - os.Exit(statuscode.Ok) + return nil } switch err.(type) { diff --git a/pkg/statuscode/statuscode.go b/pkg/statuscode/statuscode.go index f85011e..7947022 100644 --- a/pkg/statuscode/statuscode.go +++ b/pkg/statuscode/statuscode.go @@ -12,8 +12,6 @@ package statuscode const ( // Ok means everything is fine. Ok = 0 - // RenderHelp provides answers to life, the universe and everything; also, renders help. - RenderHelp = 42 // Usage means bad arguments were provided by the user. Usage = 64 // ProgrammerError means the developer made a mistake. -- 2.40.1 From 4ffa7ba364c119173d9650b165c858fa1581d274 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Wed, 19 Jun 2024 17:27:47 -0600 Subject: [PATCH 2/4] add SetOutput to logger for testing convenience --- pkg/logger/log.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/logger/log.go b/pkg/logger/log.go index 393e4da..7e19fe8 100644 --- a/pkg/logger/log.go +++ b/pkg/logger/log.go @@ -4,6 +4,7 @@ package logger import ( "context" + "io" "git.rob.mx/nidito/chinampa/pkg/runtime" "github.com/sirupsen/logrus" @@ -47,6 +48,10 @@ func Configure(name string, level Level) { } } +func SetOutput(out io.Writer) { + logrus.SetOutput(out) +} + func Debug(args ...any) { Main.Debug(args...) } -- 2.40.1 From 58b225f25e078fcad9e2ed3089cd239f07c4cfba Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Thu, 20 Jun 2024 19:37:10 -0600 Subject: [PATCH 3/4] add (opt|arg).Repeats() --- pkg/command/arguments.go | 5 +++++ pkg/command/options.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/pkg/command/arguments.go b/pkg/command/arguments.go index 1e6ec93..f60b6b8 100644 --- a/pkg/command/arguments.go +++ b/pkg/command/arguments.go @@ -182,6 +182,11 @@ func (arg *Argument) SetValue(value []string) { arg.provided = &value } +// Repeats tells if an argument should be presented as a list. +func (arg *Argument) Repeats() bool { + return arg.Variadic +} + func (arg *Argument) IsKnown() bool { return arg.provided != nil && len(*arg.provided) > 0 } diff --git a/pkg/command/options.go b/pkg/command/options.go index cc03d56..a1af3cf 100644 --- a/pkg/command/options.go +++ b/pkg/command/options.go @@ -137,6 +137,11 @@ func (opt *Option) ToString() string { return stringValue } +// Repeats tells if an option should be presented as a list. +func (opt *Option) Repeats() bool { + return opt.Repeated +} + func (opt *Option) internalValidate(name, current string) error { if current == "" { return nil -- 2.40.1 From 6c0ce602207f6896feee5083237c46175efb29d4 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Fri, 21 Jun 2024 19:38:29 -0600 Subject: [PATCH 4/4] fix formatting bugs, update deps --- go.mod | 20 +++++++++--------- go.sum | 46 ++++++++++++++++++++--------------------- pkg/logger/formatter.go | 2 +- pkg/render/render.go | 2 +- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/go.mod b/go.mod index 64732b1..2f93e7a 100644 --- a/go.mod +++ b/go.mod @@ -5,20 +5,20 @@ go 1.22 require ( github.com/charmbracelet/glamour v0.7.0 github.com/fatih/color v1.17.0 - github.com/go-playground/validator/v10 v10.20.0 + github.com/go-playground/validator/v10 v10.22.0 github.com/sirupsen/logrus v1.9.3 - github.com/spf13/cobra v1.8.0 + github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 - golang.org/x/term v0.20.0 + golang.org/x/term v0.21.0 gopkg.in/yaml.v3 v3.0.1 ) require ( - github.com/alecthomas/chroma/v2 v2.13.0 // indirect + github.com/alecthomas/chroma/v2 v2.14.0 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/dlclark/regexp2 v1.11.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gabriel-vasile/mimetype v1.4.4 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/gorilla/css v1.0.1 // indirect @@ -33,10 +33,10 @@ require ( github.com/muesli/termenv v0.15.2 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/yuin/goldmark v1.7.1 // indirect + github.com/yuin/goldmark v1.7.2 // indirect github.com/yuin/goldmark-emoji v1.0.2 // indirect - golang.org/x/crypto v0.23.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect + golang.org/x/crypto v0.24.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect ) diff --git a/go.sum b/go.sum index ed3d403..6fd1f0d 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ -github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU= -github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= -github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI= -github.com/alecthomas/chroma/v2 v2.13.0/go.mod h1:BUGjjsD+ndS6eX37YgTchSEG+Jg9Jv1GiZs9sqPqztk= +github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE= +github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= +github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E= +github.com/alecthomas/chroma/v2 v2.14.0/go.mod h1:QolEbTfmUHIMVpBqxeDnNBj2uoeI4EbYP4i6n68SG4I= github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= @@ -10,7 +10,7 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng= github.com/charmbracelet/glamour v0.7.0/go.mod h1:jUMh5MeihljJPQbJ/wf4ldw2+yBP59+ctV36jASy7ps= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4/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= @@ -18,16 +18,16 @@ github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxK github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I= +github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= -github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao= +github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= @@ -64,8 +64,8 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc 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.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= 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= @@ -73,23 +73,23 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.3.7/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U= -github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= +github.com/yuin/goldmark v1.7.2 h1:NjGd7lO7zrUn/A7eKwn5PEOt4ONYGqpxSEeZuduvgxc= +github.com/yuin/goldmark v1.7.2/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= github.com/yuin/goldmark-emoji v1.0.2 h1:c/RgTShNgHTtc6xdz2KKI74jJr6rWi7FPgnP9GAsO5s= github.com/yuin/goldmark-emoji v1.0.2/go.mod h1:RhP/RWpexdp+KHs7ghKnifRoIs/Bq4nDS7tRbCkOwKY= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= -golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= +golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= 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.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/logger/formatter.go b/pkg/logger/formatter.go index 9310292..1fe63d0 100644 --- a/pkg/logger/formatter.go +++ b/pkg/logger/formatter.go @@ -21,7 +21,7 @@ var dimmed *color.Color func init() { bold = color.New(color.Bold) bold.EnableColor() - boldRedBG = color.New(color.Bold, color.BgRed, 225) + boldRedBG = color.New(color.Bold, color.BgRed, color.FgWhite) boldRedBG.EnableColor() boldRed = color.New(color.Bold, color.FgHiRed) boldRed.EnableColor() diff --git a/pkg/render/render.go b/pkg/render/render.go index cdfe580..1daa8a2 100644 --- a/pkg/render/render.go +++ b/pkg/render/render.go @@ -42,7 +42,7 @@ func Markdown(content []byte, withColor bool) ([]byte, error) { default: // Glamour selects a style for the user. styleFunc = glamour.WithStandardStyle("auto") - if style != "" { + if style != "auto" { logger.Warnf("Unknown %s=%s, assuming \"auto\"", env.HelpStyle, style) } } -- 2.40.1