From aaa425724c52e9ca3b81b0e53bfd848a165ae28b Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 9 Jan 2019 08:26:19 +1100 Subject: [PATCH] Made init less verbose --- cmd/log.go | 38 +++++++++++++++++++++++++++++++++++++- cmd/system.go | 8 ++++++++ cmd/wails/1_init.go | 4 +--- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/cmd/log.go b/cmd/log.go index 3da1f7d2e..6d360ed8f 100644 --- a/cmd/log.go +++ b/cmd/log.go @@ -9,52 +9,88 @@ import ( // Logger struct type Logger struct { + errorOnly bool } // NewLogger creates a new logger! func NewLogger() *Logger { - return &Logger{} + return &Logger{errorOnly: false} +} + +func (l *Logger) SetErrorOnly(errorOnly bool) { + l.errorOnly = errorOnly } // Yellow - Outputs yellow text func (l *Logger) Yellow(format string, a ...interface{}) { + if l.errorOnly { + return + } color.New(color.FgHiYellow).PrintfFunc()(format+"\n", a...) } // Yellowf - Outputs yellow text without the newline func (l *Logger) Yellowf(format string, a ...interface{}) { + if l.errorOnly { + return + } + color.New(color.FgHiYellow).PrintfFunc()(format, a...) } // Green - Outputs Green text func (l *Logger) Green(format string, a ...interface{}) { + if l.errorOnly { + return + } + color.New(color.FgHiGreen).PrintfFunc()(format+"\n", a...) } // White - Outputs White text func (l *Logger) White(format string, a ...interface{}) { + if l.errorOnly { + return + } + color.New(color.FgHiWhite).PrintfFunc()(format+"\n", a...) } // WhiteUnderline - Outputs White text with underline func (l *Logger) WhiteUnderline(format string, a ...interface{}) { + if l.errorOnly { + return + } + l.White(format, a...) l.White(l.underline(format)) } // YellowUnderline - Outputs Yellow text with underline func (l *Logger) YellowUnderline(format string, a ...interface{}) { + if l.errorOnly { + return + } + l.Yellow(format, a...) l.Yellow(l.underline(format)) } // underline returns a string of a line, the length of the message given to it func (l *Logger) underline(message string) string { + if l.errorOnly { + return "" + } + return strings.Repeat("-", len(message)) } // Red - Outputs Red text func (l *Logger) Red(format string, a ...interface{}) { + if l.errorOnly { + return + } + color.New(color.FgHiRed).PrintfFunc()(format+"\n", a...) } diff --git a/cmd/system.go b/cmd/system.go index a163cc6e6..42c644a46 100644 --- a/cmd/system.go +++ b/cmd/system.go @@ -220,6 +220,13 @@ func (sc *SystemConfig) load(filename string) error { return nil } +func CheckDependenciesSilent(logger *Logger) (bool, error) { + logger.SetErrorOnly(true) + result, err := CheckDependencies(logger) + logger.SetErrorOnly(false) + return result, err +} + // CheckDependencies will look for Wails dependencies on the system // Errors are reported in error and the bool return value is whether // the dependencies are all installed. @@ -281,6 +288,7 @@ func CheckDependencies(logger *Logger) (bool, error) { } } } + logger.White("") return !errors, err } diff --git a/cmd/wails/1_init.go b/cmd/wails/1_init.go index 2ed9f0765..ce9bb23ed 100644 --- a/cmd/wails/1_init.go +++ b/cmd/wails/1_init.go @@ -34,13 +34,11 @@ Any flags that are required and not given will be prompted for.` return err } - success, err := cmd.CheckDependencies(logger) + success, err := cmd.CheckDependenciesSilent(logger) if !success { return err } - logger.White("") - // Do we want to just force defaults? if projectOptions.UseDefaults { // Use defaults