From 283e1fb8b7410bffb4b992b513e477139dddebca Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Tue, 29 Nov 2022 11:07:26 +0000 Subject: [PATCH] chore: switch to using RunE where applicable --- cmd/dx/dx.go | 7 ++----- pkg/cmd/contextcmd/context.go | 8 ++------ pkg/cmd/deletecmd/delete.go | 8 ++------ pkg/cmd/deletecmd/delete_repos.go | 8 ++------ pkg/cmd/editcmd/edit.go | 8 ++------ pkg/cmd/editcmd/edit_config.go | 7 ++----- pkg/cmd/getcmd/get.go | 8 ++------ pkg/cmd/getcmd/get_issues.go | 8 ++------ pkg/cmd/getcmd/get_prs.go | 8 ++------ pkg/cmd/getcmd/get_repos.go | 8 ++------ pkg/cmd/importcmd/import.go | 8 ++------ pkg/cmd/importcmd/import_context.go | 8 ++------ pkg/cmd/namespacecmd/namespace.go | 8 ++------ pkg/cmd/rebasecmd/rebase.go | 8 ++------ pkg/cmd/upgradecmd/upgrade.go | 8 ++------ pkg/cmd/upgradecmd/upgrade_cli.go | 7 ++----- 16 files changed, 32 insertions(+), 93 deletions(-) diff --git a/cmd/dx/dx.go b/cmd/dx/dx.go index 90e4470..7d2f63f 100644 --- a/cmd/dx/dx.go +++ b/cmd/dx/dx.go @@ -175,13 +175,10 @@ var filePrepender = func(in string) string { var docsCmd = &cobra.Command{ Use: "docs", Hidden: true, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { RootCmd.DisableAutoGenTag = true - err := doc.GenMarkdownTreeCustom(RootCmd, "./docs", filePrepender, linkHandler) - if err != nil { - fmt.Println(err) - } + return doc.GenMarkdownTreeCustom(RootCmd, "./docs", filePrepender, linkHandler) }, } diff --git a/pkg/cmd/contextcmd/context.go b/pkg/cmd/contextcmd/context.go index dad9338..0f78d11 100644 --- a/pkg/cmd/contextcmd/context.go +++ b/pkg/cmd/contextcmd/context.go @@ -1,7 +1,6 @@ package contextcmd import ( - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/pkg/errors" "github.com/plumming/dx/pkg/domain" "github.com/spf13/cobra" @@ -20,13 +19,10 @@ func NewContextCmd() *cobra.Command { Long: "", Example: "", Aliases: []string{"ctx", "c"}, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().Fatalf("unable to run command: %s", err) - } + return c.Run() }, Args: cobra.MaximumNArgs(1), } diff --git a/pkg/cmd/deletecmd/delete.go b/pkg/cmd/deletecmd/delete.go index f5098aa..e0308ba 100644 --- a/pkg/cmd/deletecmd/delete.go +++ b/pkg/cmd/deletecmd/delete.go @@ -1,7 +1,6 @@ package deletecmd import ( - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/spf13/cobra" ) @@ -19,13 +18,10 @@ func NewDeleteCmd() *cobra.Command { Short: "", Long: "", Example: "", - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().WithError(err).Fatal("unable to run command") - } + return c.Run() }, } diff --git a/pkg/cmd/deletecmd/delete_repos.go b/pkg/cmd/deletecmd/delete_repos.go index 0ce8217..9c93bad 100644 --- a/pkg/cmd/deletecmd/delete_repos.go +++ b/pkg/cmd/deletecmd/delete_repos.go @@ -5,7 +5,6 @@ import ( "github.com/plumming/dx/pkg/cmd" "github.com/plumming/dx/pkg/domain" - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/spf13/cobra" ) @@ -25,13 +24,10 @@ func NewDeleteReposCmd() *cobra.Command { Long: "", Example: "", Aliases: []string{"repositories", "repository"}, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().Fatalf("unable to run command: %s", err) - } + return c.Run() }, Args: cobra.NoArgs, } diff --git a/pkg/cmd/editcmd/edit.go b/pkg/cmd/editcmd/edit.go index a387bd3..b78dd5e 100644 --- a/pkg/cmd/editcmd/edit.go +++ b/pkg/cmd/editcmd/edit.go @@ -1,7 +1,6 @@ package editcmd import ( - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/spf13/cobra" ) @@ -19,13 +18,10 @@ func NewEditCmd() *cobra.Command { Short: "", Long: "", Example: "", - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().WithError(err).Fatal("unable to run command") - } + return c.Run() }, } diff --git a/pkg/cmd/editcmd/edit_config.go b/pkg/cmd/editcmd/edit_config.go index cb1d830..f1df141 100644 --- a/pkg/cmd/editcmd/edit_config.go +++ b/pkg/cmd/editcmd/edit_config.go @@ -26,13 +26,10 @@ func NewEditConfigCmd() *cobra.Command { Long: "", Example: "", Aliases: []string{"configuration"}, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().Fatalf("unable to run command: %s", err) - } + return c.Run() }, Args: cobra.NoArgs, } diff --git a/pkg/cmd/getcmd/get.go b/pkg/cmd/getcmd/get.go index 1f56145..752780d 100644 --- a/pkg/cmd/getcmd/get.go +++ b/pkg/cmd/getcmd/get.go @@ -1,7 +1,6 @@ package getcmd import ( - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/spf13/cobra" ) @@ -19,13 +18,10 @@ func NewGetCmd() *cobra.Command { Short: "", Long: "", Example: "", - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().WithError(err).Fatal("unable to run command") - } + return c.Run() }, } diff --git a/pkg/cmd/getcmd/get_issues.go b/pkg/cmd/getcmd/get_issues.go index 6bcd7c7..53ceb54 100644 --- a/pkg/cmd/getcmd/get_issues.go +++ b/pkg/cmd/getcmd/get_issues.go @@ -11,7 +11,6 @@ import ( "github.com/plumming/dx/pkg/util" - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/plumming/dx/pkg/table" "github.com/spf13/cobra" ) @@ -52,13 +51,10 @@ Get a list of issues with a custom query: `, Aliases: []string{"issues", "is"}, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().Fatalf("unable to run command: %s", err) - } + return c.Run() }, Args: cobra.NoArgs, } diff --git a/pkg/cmd/getcmd/get_prs.go b/pkg/cmd/getcmd/get_prs.go index a12c920..12b104e 100644 --- a/pkg/cmd/getcmd/get_prs.go +++ b/pkg/cmd/getcmd/get_prs.go @@ -11,7 +11,6 @@ import ( "github.com/plumming/dx/pkg/util" - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/plumming/dx/pkg/table" "github.com/spf13/cobra" ) @@ -53,13 +52,10 @@ Get a list of PRs with a custom query: `, Aliases: []string{"pr", "pulls", "pull-requests"}, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().Fatalf("unable to run command: %s", err) - } + return c.Run() }, Args: cobra.NoArgs, } diff --git a/pkg/cmd/getcmd/get_repos.go b/pkg/cmd/getcmd/get_repos.go index f892693..df1066a 100644 --- a/pkg/cmd/getcmd/get_repos.go +++ b/pkg/cmd/getcmd/get_repos.go @@ -5,7 +5,6 @@ import ( "github.com/plumming/dx/pkg/cmd" "github.com/plumming/dx/pkg/domain" - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/plumming/dx/pkg/table" "github.com/spf13/cobra" ) @@ -26,13 +25,10 @@ func NewGetReposCmd() *cobra.Command { Long: "", Example: "", Aliases: []string{"repositories", "repository"}, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().Fatalf("unable to run command: %s", err) - } + return c.Run() }, Args: cobra.NoArgs, } diff --git a/pkg/cmd/importcmd/import.go b/pkg/cmd/importcmd/import.go index c96e9af..bf4d1a9 100644 --- a/pkg/cmd/importcmd/import.go +++ b/pkg/cmd/importcmd/import.go @@ -1,7 +1,6 @@ package importcmd import ( - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/spf13/cobra" ) @@ -19,13 +18,10 @@ func NewImportCmd() *cobra.Command { Short: "", Long: "", Example: "", - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().WithError(err).Fatal("unable to run command") - } + return c.Run() }, } diff --git a/pkg/cmd/importcmd/import_context.go b/pkg/cmd/importcmd/import_context.go index 3f5dfcd..4321d52 100644 --- a/pkg/cmd/importcmd/import_context.go +++ b/pkg/cmd/importcmd/import_context.go @@ -1,7 +1,6 @@ package importcmd import ( - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/pkg/errors" "github.com/plumming/dx/pkg/cmd" "github.com/plumming/dx/pkg/domain" @@ -23,13 +22,10 @@ func NewImportContextCmd() *cobra.Command { Long: "", Example: "", Aliases: []string{"ctx", "c"}, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().Fatalf("unable to run command: %s", err) - } + return c.Run() }, Args: cobra.NoArgs, } diff --git a/pkg/cmd/namespacecmd/namespace.go b/pkg/cmd/namespacecmd/namespace.go index 537c237..4f63d28 100644 --- a/pkg/cmd/namespacecmd/namespace.go +++ b/pkg/cmd/namespacecmd/namespace.go @@ -1,7 +1,6 @@ package namespacecmd import ( - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/pkg/errors" "github.com/plumming/dx/pkg/domain" "github.com/spf13/cobra" @@ -20,13 +19,10 @@ func NewNamespaceCmd() *cobra.Command { Long: "", Example: "", Aliases: []string{"ns"}, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().Fatalf("unable to run command: %s", err) - } + return c.Run() }, Args: cobra.MaximumNArgs(1), } diff --git a/pkg/cmd/rebasecmd/rebase.go b/pkg/cmd/rebasecmd/rebase.go index 158cc1b..513a9af 100644 --- a/pkg/cmd/rebasecmd/rebase.go +++ b/pkg/cmd/rebasecmd/rebase.go @@ -1,7 +1,6 @@ package rebasecmd import ( - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/pkg/errors" "github.com/plumming/dx/pkg/domain" "github.com/spf13/cobra" @@ -22,13 +21,10 @@ func NewRebaseCmd() *cobra.Command { "Uses the default_branch name determined from the GitHub API.", Example: "", Aliases: []string{"rb"}, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().Fatalf("unable to run command: %s", err) - } + return c.Run() }, Args: cobra.NoArgs, } diff --git a/pkg/cmd/upgradecmd/upgrade.go b/pkg/cmd/upgradecmd/upgrade.go index 148e177..da0de86 100644 --- a/pkg/cmd/upgradecmd/upgrade.go +++ b/pkg/cmd/upgradecmd/upgrade.go @@ -1,7 +1,6 @@ package upgradecmd import ( - "github.com/jenkins-x/jx-logging/pkg/log" "github.com/spf13/cobra" ) @@ -19,13 +18,10 @@ func NewUpgradeCmd() *cobra.Command { Short: "", Long: "", Example: "", - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().WithError(err).Fatal("unable to run command") - } + return c.Run() }, } diff --git a/pkg/cmd/upgradecmd/upgrade_cli.go b/pkg/cmd/upgradecmd/upgrade_cli.go index 23c39f0..724a92d 100644 --- a/pkg/cmd/upgradecmd/upgrade_cli.go +++ b/pkg/cmd/upgradecmd/upgrade_cli.go @@ -56,13 +56,10 @@ func NewUpgradeCliCmd() *cobra.Command { Short: "Upgrade the cli", Long: "", Example: "", - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { c.Cmd = cmd c.Args = args - err := c.Run() - if err != nil { - log.Logger().Fatalf("unable to run command: %s", err) - } + return c.Run() }, Args: cobra.NoArgs, }