diff --git a/cmd/state/main.go b/cmd/state/main.go index 65e11674d2..84ae4a16fb 100644 --- a/cmd/state/main.go +++ b/cmd/state/main.go @@ -79,8 +79,14 @@ func main() { var err error cfg, err = config.New() if err != nil { - multilog.Critical("Could not initialize config: %v", errs.JoinMessage(err)) - fmt.Fprintf(os.Stderr, "Could not load config, if this problem persists please reinstall the State Tool. Error: %s\n", errs.JoinMessage(err)) + if !locale.IsInputError(err) { + multilog.Critical("Could not initialize config: %v", errs.JoinMessage(err)) + fmt.Fprintf(os.Stderr, "Could not load config, if this problem persists please reinstall the State Tool. Error: %s\n", errs.JoinMessage(err)) + } else { + for _, err2 := range locale.UnpackError(err) { + fmt.Fprintf(os.Stderr, err2.Error()) + } + } exitCode = 1 return } diff --git a/internal/logging/logging.go b/internal/logging/logging.go index 6f0c5e6f73..1ac62a772b 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -128,6 +128,7 @@ type LoggingHandler interface { type standardHandler struct { formatter Formatter + verbose bool } func (l *standardHandler) SetFormatter(f Formatter) { @@ -135,6 +136,7 @@ func (l *standardHandler) SetFormatter(f Formatter) { } func (l *standardHandler) SetVerbose(v bool) { + l.verbose = v } func (l *standardHandler) Output() io.Writer { @@ -143,7 +145,9 @@ func (l *standardHandler) Output() io.Writer { // default handling interface - just func (l *standardHandler) Emit(ctx *MessageContext, message string, args ...interface{}) error { - fmt.Fprintln(os.Stderr, l.formatter.Format(ctx, message, args...)) + if l.verbose { + fmt.Fprintln(os.Stderr, l.formatter.Format(ctx, message, args...)) + } return nil } @@ -158,6 +162,7 @@ func (l *standardHandler) Close() {} var currentHandler LoggingHandler = &standardHandler{ DefaultFormatter, + os.Getenv("VERBOSE") != "", } // Set the current handler of the library. We currently support one handler, but it might be nice to have more diff --git a/internal/osutils/user/user.go b/internal/osutils/user/user.go index 56bacb3791..1b485d0fab 100644 --- a/internal/osutils/user/user.go +++ b/internal/osutils/user/user.go @@ -23,7 +23,7 @@ func (e *HomeDirNotFoundError) Error() string { return homeDirNotFoundErrorMessage } -func (e *HomeDirNotFoundError) LocalizedError() string { +func (e *HomeDirNotFoundError) LocaleError() string { return homeDirNotFoundErrorMessage }