-
Notifications
You must be signed in to change notification settings - Fork 330
/
format.go
31 lines (27 loc) · 935 Bytes
/
format.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
package reporter
import (
"fmt"
"io"
)
var format = []string{"table", "json", "markdown", "sarif", "gh-annotations"}
func Format() []string {
return format
}
// New returns an implementation of the reporter interface depending on the format passed in
// set terminalWidth as 0 to indicate the output is not a terminal
func New(format string, stdout, stderr io.Writer, level VerbosityLevel, terminalWidth int) (Reporter, error) {
switch format {
case "json":
return NewJSONReporter(stdout, stderr, level), nil
case "table":
return NewTableReporter(stdout, stderr, level, false, terminalWidth), nil
case "markdown":
return NewTableReporter(stdout, stderr, level, true, terminalWidth), nil
case "sarif":
return NewSarifReporter(stdout, stderr, level), nil
case "gh-annotations":
return NewGHAnnotationsReporter(stdout, stderr, level), nil
default:
return nil, fmt.Errorf("%v is not a valid format", format)
}
}