/
prompt_reporter.go
85 lines (72 loc) · 1.7 KB
/
prompt_reporter.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
package prompt
import (
"os"
"strconv"
"github.com/JoaoDanielRufino/gcloc/pkg/sorter"
"github.com/olekukonko/tablewriter"
)
type PromptReporter struct {
}
func (p PromptReporter) GenerateReportByLanguage(summary *sorter.SortedSummary) error {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Language",
"Files",
"Lines",
"Blank lines",
"Comments",
"Code lines",
})
table.SetBorder(false)
table.SetAutoFormatHeaders(false)
for _, file := range summary.Results {
table.Append([]string{
file.Name,
strconv.Itoa(summary.FilesByLanguage[file.Name]),
strconv.Itoa(file.Lines),
strconv.Itoa(file.BlankLines),
strconv.Itoa(file.Comments),
strconv.Itoa(file.CodeLines),
})
}
table.SetFooter([]string{
"Total",
strconv.Itoa(summary.TotalFiles),
strconv.Itoa(summary.TotalLines),
strconv.Itoa(summary.TotalBlankLines),
strconv.Itoa(summary.TotalComments),
strconv.Itoa(summary.TotalCodeLines),
})
table.Render()
return nil
}
func (p PromptReporter) GenerateReportByFile(summary *sorter.SortedSummary) error {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Path",
"Lines",
"Blank lines",
"Comments",
"Code lines",
})
table.SetBorder(false)
table.SetAutoFormatHeaders(false)
for _, file := range summary.Results {
table.Append([]string{
file.Name,
strconv.Itoa(file.Lines),
strconv.Itoa(file.BlankLines),
strconv.Itoa(file.Comments),
strconv.Itoa(file.CodeLines),
})
}
table.SetFooter([]string{
"Total",
strconv.Itoa(summary.TotalLines),
strconv.Itoa(summary.TotalBlankLines),
strconv.Itoa(summary.TotalComments),
strconv.Itoa(summary.TotalCodeLines),
})
table.Render()
return nil
}