MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / Csv

Function Csv

cmd/format/csv.go:11–51  ·  view source on GitHub ↗
(report Report, out string)

Source from the content-addressed store, hash-verified

9)
10
11func Csv(report Report, out string) {
12
13 table := "Name, Version, Vendor, License, Language, PURL\n"
14
15 report.DepDetailGraph.ForEach(func(n *detail.DepDetailGraph) bool {
16
17 licenseTxt := ""
18 if len(n.Licenses) > 0 {
19 licenseTxt = n.Licenses[0].ShortName
20 }
21
22 formatCsv := func(s string) string {
23 if strings.Contains(s, `"`) {
24 s = strings.ReplaceAll(s, `"`, `""`)
25 }
26 if strings.Contains(s, `,`) {
27 s = fmt.Sprintf(`"%s"`, s)
28 }
29 return s
30 }
31
32 if n.Name != "" {
33 table = table + fmt.Sprintf("%s,%s,%s,%s,%s,%s\n",
34 formatCsv(n.Name),
35 formatCsv(n.Version),
36 formatCsv(n.Vendor),
37 formatCsv(licenseTxt),
38 formatCsv(n.Language),
39 formatCsv(n.Purl()),
40 )
41 }
42
43 return true
44 })
45
46 outWrite(out, func(w io.Writer) error {
47 _, err := w.Write([]byte(table))
48 return err
49 })
50
51}

Callers 1

SaveFunction · 0.85

Calls 4

outWriteFunction · 0.85
PurlMethod · 0.80
WriteMethod · 0.80
ForEachMethod · 0.45

Tested by

no test coverage detected