-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmain.go
59 lines (52 loc) · 1.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Package main implements a simple demo program to
// work with the csaf library.
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"github.com/gocsaf/csaf/v3/csaf"
"github.com/gocsaf/csaf/v3/util"
)
func main() {
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(),
"Usage:\n %s [OPTIONS] files...\n\nOptions:\n", os.Args[0])
flag.PrintDefaults()
}
idsString := flag.String("p", "", "ID1,ID2,...")
flag.Parse()
files := flag.Args()
if len(files) == 0 {
log.Println("No files given.")
return
}
if err := run(files, *idsString); err != nil {
log.Fatalf("error: %v\n", err)
}
}
// run prints PURLs belonging to the given Product IDs.
func run(files []string, ids string) error {
for _, file := range files {
adv, err := csaf.LoadAdvisory(file)
if err != nil {
return fmt.Errorf("loading %q failed: %w", file, err)
}
for _, id := range strings.Split(ids, ",") {
already := util.Set[csaf.PURL]{}
i := 0
adv.ProductTree.FindProductIdentificationHelpers(
csaf.ProductID(id),
func(h *csaf.ProductIdentificationHelper) {
if h.PURL != nil && !already.Contains(*h.PURL) {
already.Add(*h.PURL)
i++
fmt.Printf("%d. %s\n", i, *h.PURL)
}
})
}
}
return nil
}