Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Modify the return type of Statis() to optimize the output style when there is no vulnerability. #308

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cmd/format/statis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// Statis 统计概览信息
func Statis(report Report) string {
func Statis(report Report) (string, string) {

// 组件风险统计 key:0代表组件总数
depStatic := map[int]int{
Expand Down Expand Up @@ -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]), ""
}
3 changes: 2 additions & 1 deletion cmd/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading