Skip to content

Commit 2d41882

Browse files
authored
Merge pull request #2 from kuberlog/summary
Add summary as a format
2 parents 2352956 + ed45fe4 commit 2d41882

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ main.go 54 main 13
9292
main_test.go 54 TestSomething 9
9393
```
9494

95+
#### Summary
96+
```shell
97+
$ abcgo -path ./ -format summary
98+
A B C
99+
Project summary: 22 43 15
100+
```
101+
95102
### Options
96103

97104
* `-path [path]` - Path to file or directory.

main.go

+16
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func main() {
7171
}
7272

7373
switch format {
74+
case "summary":
75+
reports.renderSummary()
7476
case "table":
7577
reports.renderTable()
7678
case "json":
@@ -170,6 +172,20 @@ func (report *Report) Calc() {
170172
report.Score = int(math.Sqrt(a + b + c))
171173
}
172174

175+
func (reports Reports) renderSummary() {
176+
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
177+
defer w.Flush()
178+
a, b, c := 0, 0, 0
179+
for _, report := range reports {
180+
a = a + report.Assignment
181+
b = b + report.Branch
182+
c = c + report.Condition
183+
}
184+
185+
fmt.Fprintln(w, "\tA\tB\tC")
186+
fmt.Fprintf(w, "%s\t%d\t%d\t%d\n", "Project summary:", a, b, c)
187+
}
188+
173189
func (reports Reports) renderTable() {
174190
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
175191
defer w.Flush()

0 commit comments

Comments
 (0)