-
Notifications
You must be signed in to change notification settings - Fork 150
/
output.go
97 lines (84 loc) · 1.91 KB
/
output.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package output
import (
"sort"
"github.com/snyk/driftctl/pkg/analyser"
"github.com/snyk/driftctl/pkg/output"
)
type Output interface {
Write(analysis *analyser.Analysis) error
}
var supportedOutputTypes = []string{
ConsoleOutputType,
JSONOutputType,
HTMLOutputType,
PlanOutputType,
}
var supportedOutputExample = map[string]string{
ConsoleOutputType: ConsoleOutputExample,
JSONOutputType: JSONOutputExample,
HTMLOutputType: HTMLOutputExample,
PlanOutputType: PlanOutputExample,
}
func SupportedOutputsExample() []string {
examples := make([]string, 0, len(supportedOutputExample))
for _, ex := range supportedOutputExample {
examples = append(examples, ex)
}
sort.Strings(examples)
return examples
}
func Example(key string) string {
return supportedOutputExample[key]
}
func IsSupported(key string) bool {
for _, o := range supportedOutputTypes {
if o == key {
return true
}
}
return false
}
func GetOutput(config OutputConfig) Output {
switch config.Key {
case JSONOutputType:
return NewJSON(config.Path)
case HTMLOutputType:
return NewHTML(config.Path)
case PlanOutputType:
return NewPlan(config.Path)
case ConsoleOutputType:
fallthrough
default:
return NewConsole()
}
}
// ShouldPrint indicate if we should use the global output or not (e.g. when outputting to stdout).
func ShouldPrint(outputs []OutputConfig, quiet bool) bool {
for _, c := range outputs {
p := GetPrinter(c, quiet)
if _, ok := p.(*output.VoidPrinter); ok {
return false
}
}
return true
}
func GetPrinter(config OutputConfig, quiet bool) output.Printer {
if quiet {
return &output.VoidPrinter{}
}
switch config.Key {
case JSONOutputType:
fallthrough
case PlanOutputType:
fallthrough
case HTMLOutputType:
fallthrough
case ConsoleOutputType:
fallthrough
default:
return output.NewConsolePrinter()
}
}
func isStdOut(path string) bool {
return path == "/dev/stdout" || path == "stdout"
}