-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
73 lines (59 loc) · 1.82 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"flag"
"fmt"
"os"
"github.com/gookit/color"
"github.com/kubecolor/kubecolor/config"
)
var (
colorErrorPrefix = config.MustParseColor("hi-red:bold")
colorErrorText = config.MustParseColor("red")
colorWarnPrefix = config.MustParseColor("hi-yellow:bold")
colorWarnText = config.MustParseColor("yellow")
colorHeader = config.MustParseColor("bold")
colorMuted = config.MustParseColor("gray")
colorSuccess = config.MustParseColor("green")
colorDiffAddPrefix = config.MustParseColor("fg=green:bg=22:bold")
colorDiffAdd = config.MustParseColor("bg=22") // dark green
colorDiffDelPrefix = config.MustParseColor("fg=red:bg=52:bold")
colorDiffDel = config.MustParseColor("bg=52") // dark red
colorDiffEqual = config.MustParseColor("gray:italic")
colorDiffColorHighlight = config.MustParseColor(`magenta`)
)
var flags = struct {
glob string
update bool
}{
glob: "test/corpus/*.txt",
}
func init() {
flag.StringVar(&flags.glob, "glob", flags.glob, "Glob pattern to find test files")
flag.BoolVar(&flags.update, "update", flags.update, "Update all outputs in corpus files with current kubecolor output")
color.ForceColor()
color.Enable = true
}
func main() {
flag.Parse()
fmt.Println()
files, err := ParseGlob(flags.glob)
if err != nil {
logErrorf("%s", err)
os.Exit(1)
}
if len(files) == 0 {
logWarnf("glob did not match any files: %s", flags.glob)
os.Exit(0)
}
if flags.update {
UpdateTests(files)
} else {
RunTests(files)
}
}
func logErrorf(format string, args ...any) {
fmt.Printf(" %s %s\n", colorErrorPrefix.Render("error:"), colorErrorText.Render(fmt.Sprintf(format, args...)))
}
func logWarnf(format string, args ...any) {
fmt.Printf(" %s %s\n", colorWarnPrefix.Render("warn:"), colorWarnText.Render(fmt.Sprintf(format, args...)))
}