From ef4b24f068a140dd28f5d0c8cd90c4841d64e989 Mon Sep 17 00:00:00 2001 From: bytedream Date: Mon, 28 Feb 2022 16:38:56 +0100 Subject: [PATCH] Removed color flag and changed error output format --- cmd/crunchyroll-go/cmd/root.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/cmd/crunchyroll-go/cmd/root.go b/cmd/crunchyroll-go/cmd/root.go index 6f8a4e6..db2cba6 100644 --- a/cmd/crunchyroll-go/cmd/root.go +++ b/cmd/crunchyroll-go/cmd/root.go @@ -5,20 +5,17 @@ import ( "github.com/spf13/cobra" "net/http" "os" - "runtime" "runtime/debug" ) var ( client *http.Client - locale crunchyroll.LOCALE crunchy *crunchyroll.Crunchyroll - out = newLogger(false, true, true, colorFlag) + out = newLogger(false, true, true) quietFlag bool verboseFlag bool proxyFlag string - colorFlag bool ) var rootCmd = &cobra.Command{ @@ -26,9 +23,9 @@ var rootCmd = &cobra.Command{ Short: "Download crunchyroll videos with ease", PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) { if verboseFlag { - out = newLogger(true, true, true, colorFlag) + out = newLogger(true, true, true) } else if quietFlag { - out = newLogger(false, false, false, false) + out = newLogger(false, false, false) } out.DebugLog.Printf("Executing `%s` command with %d arg(s)\n", cmd.Name(), len(args)) @@ -42,23 +39,21 @@ func init() { rootCmd.PersistentFlags().BoolVarP(&quietFlag, "quiet", "q", false, "Disable all output") rootCmd.PersistentFlags().BoolVarP(&verboseFlag, "verbose", "v", false, "Adds debug messages to the normal output") rootCmd.PersistentFlags().StringVarP(&proxyFlag, "proxy", "p", "", "Proxy to use") - rootCmd.PersistentFlags().BoolVar(&colorFlag, "color", false, "Colored output. Only available on not windows systems") } func Execute() { rootCmd.CompletionOptions.DisableDefaultCmd = true defer func() { if r := recover(); r != nil { - out.Errln(r) - // change color to red - if colorFlag && runtime.GOOS != "windows" { - out.ErrLog.SetOutput(&loggerWriter{original: out.ErrLog.Writer(), color: "\033[31m"}) + if out.IsDev() { + out.Err(string(debug.Stack())) + } else { + out.Err("Unexpected error: %v", r) } - out.Debugln(string(debug.Stack())) - os.Exit(2) + os.Exit(1) } }() - if err := rootCmd.Execute(); err != nil { - out.Fatalln(err) + if rootCmd.Execute() != nil { + os.Exit(1) } }