Skip to content

Commit 2c09408

Browse files
Merge pull request #308 from cyberchen1995/cc-dev
chore: Modify the return type of Statis() to optimize the output style when there is no vulnerability.
2 parents be534bb + 0c48ab9 commit 2c09408

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

cmd/format/statis.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
// Statis 统计概览信息
10-
func Statis(report Report) string {
10+
func Statis(report Report) (string, string) {
1111

1212
// 组件风险统计 key:0代表组件总数
1313
depStatic := map[int]int{
@@ -50,10 +50,11 @@ func Statis(report Report) string {
5050

5151
return true
5252
})
53-
54-
return fmt.Sprintf("Components:%d C:%d H:%d M:%d L:%d\n"+
55-
"Vulnerabilities:%d C:%d H:%d M:%d L:%d",
56-
depStatic[0], depStatic[1], depStatic[2], depStatic[3], depStatic[4],
57-
vulStatic[0], vulStatic[1], vulStatic[2], vulStatic[3], vulStatic[4],
58-
)
53+
if vulStatic[0] != 0 {
54+
return fmt.Sprintf("Components:%d C:%d H:%d M:%d L:%d",
55+
depStatic[0], depStatic[1], depStatic[2], depStatic[3], depStatic[4]),
56+
fmt.Sprintf("\nVulnerabilities:%d C:%d H:%d M:%d L:%d",
57+
vulStatic[0], vulStatic[1], vulStatic[2], vulStatic[3], vulStatic[4])
58+
}
59+
return fmt.Sprintf("Components: %d", depStatic[0]), ""
5960
}

cmd/ui/ui.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ func OpenUI(report format.Report) {
9393
}
9494

9595
func TaskInfo(report format.Report) *tview.TextView {
96+
dep, vul := format.Statis(report)
9697
info := tview.NewTextView().
97-
SetText(format.Statis(report))
98+
SetText(fmt.Sprintf("%s\n%s", dep, vul))
9899
info.SetTextColor(tcell.ColorBlue)
99100
return info
100101
}

main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ func main() {
8888
}
8989

9090
// 打印概览信息
91-
fmt.Println("\n\nComplete!\n" + format.Statis(report))
92-
logs.Info("\nComplete!\n" + format.Statis(report))
91+
dep, vul := format.Statis(report)
92+
fmt.Println("\nComplete!\n" + dep + vul)
93+
logs.Info("\nComplete!\n" + dep + vul)
9394

9495
// 发送检测报告
9596
if err := format.Saas(report); err != nil {

0 commit comments

Comments
 (0)