mirror of
https://github.com/outbackdingo/ghorg.git
synced 2026-01-27 10:19:03 +00:00
70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
// Package colorlog has various Print functions that can be called to change the color of the text in standard out
|
|
package colorlog
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/fatih/color"
|
|
)
|
|
|
|
// PrintInfo prints yellow colored text to standard out
|
|
func PrintInfo(msg interface{}) {
|
|
if os.Getenv("GHORG_QUIET") == "true" {
|
|
return
|
|
}
|
|
|
|
switch os.Getenv("GHORG_COLOR") {
|
|
case "enabled":
|
|
color.New(color.FgYellow).Println(msg)
|
|
default:
|
|
fmt.Println(msg)
|
|
}
|
|
}
|
|
|
|
// PrintSuccess prints green colored text to standard out
|
|
func PrintSuccess(msg interface{}) {
|
|
switch os.Getenv("GHORG_COLOR") {
|
|
case "enabled":
|
|
color.New(color.FgGreen).Println(msg)
|
|
default:
|
|
fmt.Println(msg)
|
|
}
|
|
}
|
|
|
|
// PrintError prints red colored text to standard out
|
|
func PrintError(msg interface{}) {
|
|
switch os.Getenv("GHORG_COLOR") {
|
|
case "enabled":
|
|
color.New(color.FgRed).Println(msg)
|
|
default:
|
|
fmt.Println(msg)
|
|
}
|
|
}
|
|
|
|
// PrintErrorAndExit prints red colored text to standard out then exits 1
|
|
func PrintErrorAndExit(msg interface{}) {
|
|
switch os.Getenv("GHORG_COLOR") {
|
|
case "enabled":
|
|
color.New(color.FgRed).Println(msg)
|
|
default:
|
|
fmt.Println(msg)
|
|
}
|
|
|
|
os.Exit(1)
|
|
}
|
|
|
|
// PrintSubtleInfo prints magenta colored text to standard out
|
|
func PrintSubtleInfo(msg interface{}) {
|
|
if os.Getenv("GHORG_QUIET") == "true" {
|
|
return
|
|
}
|
|
|
|
switch os.Getenv("GHORG_COLOR") {
|
|
case "enabled":
|
|
color.New(color.FgHiMagenta).Println(msg)
|
|
default:
|
|
fmt.Println(msg)
|
|
}
|
|
}
|