-
Notifications
You must be signed in to change notification settings - Fork 55
/
format_singleline.go
52 lines (42 loc) · 1.21 KB
/
format_singleline.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
package formatters
import (
"bytes"
"fmt"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/load"
)
type SingleLineFormatter struct {
notImplementedFormatter
Localizer checker.Localizer
}
func newSingleLineFormatter(l checker.Localizer) SingleLineFormatter {
return SingleLineFormatter{
Localizer: l,
}
}
func (f SingleLineFormatter) RenderChangelog(changes checker.Changes, opts RenderOpts, specInfoPair *load.SpecInfoPair) ([]byte, error) {
result := bytes.NewBuffer(nil)
if len(changes) > 0 {
_, _ = fmt.Fprint(result, getChangelogTitle(changes, f.Localizer, opts.ColorMode))
}
for _, c := range changes {
_, _ = fmt.Fprintf(result, "%s\n\n", c.SingleLineError(f.Localizer, opts.ColorMode))
}
return result.Bytes(), nil
}
func (f SingleLineFormatter) SupportedOutputs() []Output {
return []Output{OutputChangelog}
}
func getChangelogTitle(changes checker.Changes, l checker.Localizer, colorMode checker.ColorMode) string {
count := changes.GetLevelCount()
return l(
"total-changes",
len(changes),
count[checker.ERR],
checker.ERR.StringCond(colorMode),
count[checker.WARN],
checker.WARN.StringCond(colorMode),
count[checker.INFO],
checker.INFO.StringCond(colorMode),
)
}