From e2260b695686da32ac9938e79c16af10eb680903 Mon Sep 17 00:00:00 2001 From: Daniele Rondina Date: Sat, 27 Jun 2020 16:45:42 +0200 Subject: [PATCH] Add --no-spinner option --- cmd/root.go | 9 ++++++++- pkg/logger/logger.go | 28 ++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index ebcfe60d..31696d22 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -88,8 +88,12 @@ func LoadConfig(c *config.LuetConfig) error { return err } + noSpinner := c.Viper.GetBool("no_spinner") + InitAurora() - NewSpinner() + if !noSpinner { + NewSpinner() + } Debug("Using config file:", c.Viper.ConfigFileUsed()) @@ -145,6 +149,7 @@ func init() { pflags.BoolP("debug", "d", false, "verbose output") pflags.Bool("fatal", false, "Enables Warnings to exit") pflags.Bool("enable-logfile", false, "Enable log to file") + pflags.Bool("no-spinner", false, "Disable spinner.") pflags.Bool("color", config.LuetCfg.GetLogging().Color, "Enable/Disable color.") pflags.Bool("emoji", config.LuetCfg.GetLogging().EnableEmoji, "Enable/Disable emoji.") pflags.StringP("logfile", "l", config.LuetCfg.GetLogging().Path, @@ -168,6 +173,8 @@ func init() { config.LuetCfg.Viper.BindPFlag("general.debug", pflags.Lookup("debug")) config.LuetCfg.Viper.BindPFlag("general.fatal_warnings", pflags.Lookup("fatal")) config.LuetCfg.Viper.BindPFlag("general.same_owner", pflags.Lookup("same-owner")) + // Currently I maintain this only from cli. + config.LuetCfg.Viper.BindPFlag("no_spinner", pflags.Lookup("no-spinner")) // Extensions must be binary with the "luet-" prefix to be able to be shown in the help. // we also accept extensions in the relative path where luet is being started, "extensions/" diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 00830fd2..31d3d922 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -78,23 +78,25 @@ func Spinner(i int) { i = 43 } - if !s.Active() { + if s != nil && !s.Active() { // s.UpdateCharSet(spinner.CharSets[i]) s.Start() // Start the spinner } } func SpinnerText(suffix, prefix string) { - s.Lock() - defer s.Unlock() - if LuetCfg.GetGeneral().Debug { - fmt.Println(fmt.Sprintf("%s %s", - Bold(Cyan(prefix)).String(), - Bold(Magenta(suffix)).BgBlack().String(), - )) - } else { - s.Suffix = Bold(Magenta(suffix)).BgBlack().String() - s.Prefix = Bold(Cyan(prefix)).String() + if s != nil { + s.Lock() + defer s.Unlock() + if LuetCfg.GetGeneral().Debug { + fmt.Println(fmt.Sprintf("%s %s", + Bold(Cyan(prefix)).String(), + Bold(Magenta(suffix)).BgBlack().String(), + )) + } else { + s.Suffix = Bold(Magenta(suffix)).BgBlack().String() + s.Prefix = Bold(Cyan(prefix)).String() + } } } @@ -108,7 +110,9 @@ func SpinnerStop() { if 2 > confLevel { return } - s.Stop() + if s != nil { + s.Stop() + } } func level2Number(level string) int {