-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisten_helm_debug.go
54 lines (46 loc) · 1.25 KB
/
listen_helm_debug.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
package main
import (
"bufio"
"flag"
"io"
"log"
"os"
"regexp"
)
var debugLineRegex = regexp.MustCompile(`.+\[debug\]\s*(?P<debug_log>.*)$`)
// TODO: also warnings?
func printIfDebugLine(output io.Writer, line []byte) {
result := debugLineRegex.FindSubmatch(line)
if len(result) > 0 {
debugLog := result[len(result)-1]
_, err := output.Write(append(debugLog, []byte("\n")...))
panicOnError(err)
}
}
func listenHelmDebug(input *bufio.Scanner, output io.Writer, args []string) {
flag := flag.NewFlagSet(LISTEN_HELM_DEBUG_CMD_NAME, flag.ExitOnError)
err := flag.Parse(args)
if err != nil {
log.Fatal(err)
}
_, err = output.Write([]byte("\x1b[0;33mcicdbox: Only Helm debug logs will be displayed...\x1b[0m\n"))
panicOnError(err)
var outputToCollapse []string
for input.Scan() {
rawLine := input.Bytes()
// Keep for the end
outputToCollapse = append(outputToCollapse, string(rawLine))
printIfDebugLine(output, rawLine)
}
echoCollapsed(output, "\x1b[0;33mExpand to see the entire output.\x1b[0m", outputToCollapse)
if err := input.Err(); err != nil {
log.Fatal(err)
}
}
func ListenHelmDebug(args []string) {
// read stdin
input := bufio.NewScanner(os.Stdin)
// write to stdout
output := os.Stdout
listenHelmDebug(input, output, args)
}