mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Removed color flag and changed error output format
This commit is contained in:
parent
9fbb3266aa
commit
ef4b24f068
1 changed files with 10 additions and 15 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue