diff --git a/tools/component/component.go b/tools/component/component.go index f9170db87..6429cf04e 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -65,6 +65,24 @@ type checkFunc struct { config *config.GlobalConfig } +// colorErrPrint prints formatted string in red to stderr +func colorErrPrint(format string, a ...interface{}) { + // ANSI escape code for red text + const redColor = "\033[31m" + // ANSI escape code to reset color + const resetColor = "\033[0m" + // Format the string as per provided format and arguments + errMsg := fmt.Sprintf(format, a...) + // Print to stderr in red + fmt.Fprintf(os.Stderr, redColor+errMsg+resetColor) +} + +func colorSuccessPrint(format string, a ...interface{}) { + // ANSI escape code for green text is \033[32m + // \033[0m resets the color + fmt.Printf("\033[32m"+format+"\033[0m", a...) +} + func main() { flag.Parse() @@ -102,16 +120,16 @@ func main() { err = check.function(check.config) if err != nil { allSuccess = false - component.ErrorPrint(fmt.Sprintf("Check component: %s, failed: %s", check.name, err.Error())) + colorErrPrint(fmt.Sprintf("Check component: %s, failed: %s", check.name, err.Error())) if check.name == "Minio" { if errors.Is(err, errMinioNotEnabled) || errors.Is(err, errSignEndPoint) || errors.Is(err, errApiURL) { - fmt.Fprintf(os.Stderr, err.Error(), " check ", check.name) + colorErrPrint("Check ", check.name, err.Error()) checks[index].flag = true continue } - break + break } } else { checks[index].flag = true