This repository has been archived by the owner on May 27, 2019. It is now read-only.
/
console.go
78 lines (61 loc) · 1.79 KB
/
console.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
package reports
import (
"fmt"
"github.com/olekukonko/tablewriter"
"golang.org/x/crypto/ssh/terminal"
"os"
"strings"
)
// ConsoleReport is a type of text-based report that writes to stdout.
type ConsoleReport struct{}
// Generate generates a text-based report.
func (cr *ConsoleReport) Generate(report *Report) {
issues := sortedIssues(report.Issues)
width, _, err := terminal.GetSize(0)
if err != nil {
width = 70
}
cr.println("")
cr.println("=== Start SolAnalyzer Report ===")
cr.println("")
cr.println("Report Date: %s", report.GeneratedAt.Format("Mon Jan _2 3:04 PM 2006"))
cr.println("Analyzers Run: %s", report.AnalyzersRun())
cr.println("")
for i := len(issues) - 1; i >= 0; i-- {
cr.printHeader(fmt.Sprintf("%s Severity Issues", severityAsWord(i)))
if len(issues[i]) == 0 {
cr.println("No issues")
cr.println("")
continue
}
cr.println("")
for _, issue := range issues[i] {
table := tablewriter.NewWriter(os.Stdout)
table.SetColWidth(width - 18)
table.SetBorder(false)
table.SetColumnSeparator("")
table.Append([]string{"Title", issue.Title})
switch issue.Format {
case "txt":
table.Append([]string{"Description", issue.Message})
case "dot":
table.Append([]string{"Description",
processDot(issue.AnalyzerID(), []byte(issue.Message))})
}
table.Append([]string{"Source", issue.Source()})
table.Append([]string{"Analyzer ID", issue.AnalyzerID()})
table.Append([]string{"Instance ID", issue.ID()})
table.Render()
cr.println("")
}
}
cr.println("=== End SolAnalyzer Report ===")
cr.println("")
}
func (cr *ConsoleReport) printHeader(str string) {
fmt.Println(str)
fmt.Println(strings.Repeat("-", len(str)))
}
func (cr *ConsoleReport) println(str string, vars ...interface{}) {
fmt.Println(fmt.Sprintf(str, vars...))
}