-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathprinter.go
More file actions
85 lines (73 loc) · 2.46 KB
/
printer.go
File metadata and controls
85 lines (73 loc) · 2.46 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
package printer
import (
"fmt"
"io"
"strings"
"github.com/get-woke/woke/pkg/result"
env "github.com/caitlinelfring/go-env-default"
config "github.com/get-woke/woke/pkg/config"
"github.com/rs/zerolog/log"
)
// Printer is an interface for printing FileResults
type Printer interface {
Print(*result.FileResults) error
Start()
End()
PrintSuccessExitMessage() bool
}
const (
// OutFormatText is a text-based output format, best for CLIs
OutFormatText = "text"
// OutFormatSimple is a simplified output format, which can be used with something like https://github.com/reviewdog/reviewdog
OutFormatSimple = "simple"
// OutFormatGitHubActions is an output format supported by GitHub Actions annotations
// https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message
OutFormatGitHubActions = "github-actions"
// OutFormatJSON outputs in json
OutFormatJSON = "json"
// OutFormatSonarQube is an output format supported by SonarQube
// https://docs.sonarqube.org/latest/analysis/generic-issue/
OutFormatSonarQube = "sonarqube"
// OutFormatPrometheus outputs in prometheus format
// https://prometheus.io/docs/instrumenting/writing_exporters/
OutFormatPrometheus = "prometheus"
// OutFormatCheckstyle outputs in checkstyle format.
// https://github.com/checkstyle/checkstyle
OutFormatCheckstyle = "checkstyle"
)
// OutFormats are all the available output formats. The first one should be the default
var OutFormats = []string{
OutFormatText,
OutFormatSimple,
OutFormatGitHubActions,
OutFormatJSON,
OutFormatSonarQube,
OutFormatPrometheus,
OutFormatCheckstyle,
}
// OutFormatsString is all OutFormats, as a comma-separated string
var OutFormatsString = strings.Join(OutFormats, ",")
// NewPrinter returns a valid new Printer from a string, or an error if the printer is invalid
func NewPrinter(f string, w io.Writer, c *config.Config) (Printer, error) {
var p Printer
switch f {
case OutFormatText:
p = NewText(w, env.GetBoolDefault("DISABLE_COLORS", false))
case OutFormatSimple:
p = NewSimple(w)
case OutFormatGitHubActions:
p = NewGitHubActions(w)
case OutFormatJSON:
p = NewJSON(w)
case OutFormatSonarQube:
p = NewSonarQube(w)
case OutFormatPrometheus:
p = NewPrometheus(w, c.Outputs.Prometheus)
case OutFormatCheckstyle:
p = NewCheckstyle(w)
default:
return p, fmt.Errorf("%s is not a valid printer type", f)
}
log.Debug().Str("printer", f).Msg("created new printer")
return p, nil
}