-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
41 lines (34 loc) · 991 Bytes
/
util.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
37
38
39
40
41
package main
import (
"fmt"
"log"
"os"
"github.com/mgutz/ansi"
)
// exists returns whether the given file or directory exists or not
func fileExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
func printError(message string, args ...interface{}) {
log.Println(colorizeMessage("red", "error:", message, args...))
}
func printFatal(message string, args ...interface{}) {
log.Fatal(colorizeMessage("red", "error:", message, args...))
}
func printWarning(message string, args ...interface{}) {
log.Println(colorizeMessage("yellow", "warning:", message, args...))
}
func colorizeMessage(color, prefix, message string, args ...interface{}) string {
prefResult := ""
if prefix != "" {
prefResult = ansi.Color(prefix, color+"+b") + " " + ansi.ColorCode("reset")
}
return prefResult + ansi.Color(fmt.Sprintf(message, args...), color) + ansi.ColorCode("reset")
}