-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
58 lines (51 loc) · 1.18 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
package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"flag"
"strings"
"github.com/ladydascalie/gorgeous/filters"
)
var prefix string
var isJSON bool
// testOutput represents the JSON output of a test.
type testOutput struct {
Time string `json:"Time"`
Action string `json:"Action"`
Package string `json:"Package"`
Output string `json:"Output"`
}
func main() {
flag.StringVar(&prefix, "prefix", "", "give a prefix you want to automatically strip away (useful with docker-compose logs)")
flag.BoolVar(&isJSON, "json", false, "pass this flag if you are dealing with JSON test output (defaults to false)")
flag.Parse()
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
switch isJSON {
case true:
var out testOutput
if err := json.Unmarshal(scanner.Bytes(), &out); err != nil {
log.Fatalln(err)
}
for _, f := range filters.All {
txt := strings.TrimSuffix(out.Output, "\n")
if t := f(txt); t != "" {
fmt.Println(t)
}
}
default:
txt := scanner.Text()
if prefix != "" {
txt = strings.TrimPrefix(txt, prefix)
}
for _, f := range filters.All {
if t := f(txt); t != "" {
fmt.Println(t)
}
}
}
}
}