forked from nomad-software/meme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
36 lines (29 loc) · 750 Bytes
/
output.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package output
import (
"fmt"
"os"
"github.com/fatih/color"
"github.com/mattn/go-colorable"
)
var (
// Stdout is a color friendly pipe.
Stdout = colorable.NewColorableStdout()
// Stderr is a color friendly pipe.
Stderr = colorable.NewColorableStderr()
)
// OnError prints an error if err is not nil and exits the program.
func OnError(err error, text string) {
if err != nil {
fmt.Fprintln(Stderr, color.RedString(text+": %s", err.Error()))
os.Exit(1)
}
}
// Error prints an error and exits the program.
func Error(text string) {
fmt.Fprintln(Stderr, color.RedString(text))
os.Exit(1)
}
// Info prints information.
func Info(format string, args ...interface{}) {
fmt.Fprintf(Stdout, color.GreenString(format)+"\n", args...)
}