From fd9fa5a03e16932d037a76d8b5383a52a46c10f4 Mon Sep 17 00:00:00 2001 From: CyberChen Date: Mon, 27 Jan 2025 20:25:27 +0800 Subject: [PATCH] chore: Modify the return type of Statis() to optimize the output style when there is no vulnerability. --- cmd/format/statis.go | 15 ++++++++------- cmd/ui/ui.go | 3 ++- main.go | 5 +++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cmd/format/statis.go b/cmd/format/statis.go index 14911f51..98296333 100644 --- a/cmd/format/statis.go +++ b/cmd/format/statis.go @@ -7,7 +7,7 @@ import ( ) // Statis 统计概览信息 -func Statis(report Report) string { +func Statis(report Report) (string, string) { // 组件风险统计 key:0代表组件总数 depStatic := map[int]int{ @@ -50,10 +50,11 @@ func Statis(report Report) string { return true }) - - return fmt.Sprintf("Components:%d C:%d H:%d M:%d L:%d\n"+ - "Vulnerabilities:%d C:%d H:%d M:%d L:%d", - depStatic[0], depStatic[1], depStatic[2], depStatic[3], depStatic[4], - vulStatic[0], vulStatic[1], vulStatic[2], vulStatic[3], vulStatic[4], - ) + if vulStatic[0] != 0 { + return fmt.Sprintf("Components:%d C:%d H:%d M:%d L:%d", + depStatic[0], depStatic[1], depStatic[2], depStatic[3], depStatic[4]), + fmt.Sprintf("\nVulnerabilities:%d C:%d H:%d M:%d L:%d", + vulStatic[0], vulStatic[1], vulStatic[2], vulStatic[3], vulStatic[4]) + } + return fmt.Sprintf("Components: %d", depStatic[0]), "" } diff --git a/cmd/ui/ui.go b/cmd/ui/ui.go index a7af9048..5db85c6b 100644 --- a/cmd/ui/ui.go +++ b/cmd/ui/ui.go @@ -93,8 +93,9 @@ func OpenUI(report format.Report) { } func TaskInfo(report format.Report) *tview.TextView { + dep, vul := format.Statis(report) info := tview.NewTextView(). - SetText(format.Statis(report)) + SetText(fmt.Sprintf("%s\n%s", dep, vul)) info.SetTextColor(tcell.ColorBlue) return info } diff --git a/main.go b/main.go index 780b1828..0ab392ca 100644 --- a/main.go +++ b/main.go @@ -88,8 +88,9 @@ func main() { } // 打印概览信息 - fmt.Println("\n\nComplete!\n" + format.Statis(report)) - logs.Info("\nComplete!\n" + format.Statis(report)) + dep, vul := format.Statis(report) + fmt.Println("\nComplete!\n" + dep + vul) + logs.Info("\nComplete!\n" + dep + vul) // 发送检测报告 if err := format.Saas(report); err != nil {