From 2f920891919fe324be33afe747919dc94716145c Mon Sep 17 00:00:00 2001 From: Seednode Date: Fri, 27 Jan 2023 13:20:07 -0600 Subject: [PATCH] Replaced Run with RunE in rootcmd, to cascade errors back to main Execute() --- cmd/root.go | 9 ++++++--- cmd/version.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 35ca96b..4da3778 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,7 +5,7 @@ Copyright © 2023 Seednode package cmd import ( - "log" + "fmt" "os" "github.com/spf13/cobra" @@ -24,11 +24,13 @@ var ( Use: "roulette [path]...", Short: "Serves random images from the specified directories.", Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { err := ServePage(args) if err != nil { - log.Fatal(err) + return err } + + return nil }, } ) @@ -36,6 +38,7 @@ var ( func Execute() { err := rootCmd.Execute() if err != nil { + fmt.Println(err) os.Exit(1) } } diff --git a/cmd/version.go b/cmd/version.go index 5eb1301..dafe543 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.34.1" +var Version = "0.34.2" func init() { rootCmd.AddCommand(versionCmd)