77 "path/filepath"
88 "strings"
99
10+ "github.com/xmirrorsecurity/opensca-cli/v3/cmd/config"
1011 "github.com/xmirrorsecurity/opensca-cli/v3/cmd/detail"
1112 "github.com/xmirrorsecurity/opensca-cli/v3/opensca/logs"
1213)
@@ -37,7 +38,7 @@ func Save(report Report, output string) {
3738 logs .Infof ("result save to %s" , out )
3839 switch filepath .Ext (out ) {
3940 case ".html" :
40- Html (report , out )
41+ Html (genReport ( report ) , out )
4142 case ".json" :
4243 if strings .HasSuffix (out , ".spdx.json" ) {
4344 SpdxJson (report , out )
@@ -48,7 +49,7 @@ func Save(report Report, output string) {
4849 } else if strings .HasSuffix (out , ".swid.json" ) {
4950 SwidJson (report , out )
5051 } else {
51- Json (report , out )
52+ Json (genReport ( report ) , out )
5253 }
5354 case ".dsdx" :
5455 Dsdx (report , out )
@@ -73,11 +74,30 @@ func Save(report Report, output string) {
7374 case ".sarif" :
7475 Sarif (report , out )
7576 default :
76- Json (report , out )
77+ Json (genReport ( report ) , out )
7778 }
7879 }
7980}
8081
82+ func genReport (report Report ) Report {
83+ optional := config .Conf ().Optional
84+ var newReport = report
85+ if optional .VulnOnly {
86+ var deps []* detail.DepDetailGraph
87+ report .DepDetailGraph .ForEach (func (n * detail.DepDetailGraph ) bool {
88+ if len (n .Vulnerabilities ) > 0 {
89+ deps = append (deps , n )
90+ }
91+ return true
92+ })
93+ for _ , d := range deps {
94+ d .Children = nil
95+ }
96+ newReport .DepDetailGraph = & detail.DepDetailGraph {Children : deps }
97+ }
98+ return newReport
99+ }
100+
81101func outWrite (out string , do func (io.Writer ) error ) {
82102
83103 if out == "" {
0 commit comments