From 51e6c01c5abc533a79f34f4f9ecb1cad00865308 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Wed, 19 Jun 2024 14:16:10 -0600 Subject: [PATCH] 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.