-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (51 loc) · 936 Bytes
/
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
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/s-index/go-cve-search/nvd"
"github.com/urfave/cli/v2"
)
var (
version = "0.1.0"
)
func main() {
app := &cli.App{
Name: "go-cve-search",
Usage: "search CVE",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Show version",
},
&cli.BoolFlag{
Name: "pretty",
Aliases: []string{"p"},
Usage: "Pretty Print Json",
},
},
Action: func(c *cli.Context) error {
if c.Bool("version") {
fmt.Println("go-cve-search v" + version)
return nil
}
nvd, err := nvd.FetchNVD(c.Args().Get(0))
if err != nil {
return err
}
if c.Bool("pretty") {
prettyNvd, _ := json.MarshalIndent(nvd, "", " ")
fmt.Println(string(prettyNvd))
return nil
}
fmt.Println(nvd)
return nil
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}