-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
52 lines (44 loc) · 1.12 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
package main
import (
"io"
"log"
"os"
"github.com/spf13/cobra"
"golang.org/x/xerrors"
"github.com/afdesk/scan2html/render"
)
func main() {
rootCmd, err := initRootCmd()
if err != nil {
log.Fatalf("error initialising root cmd %+v", err)
}
if err = rootCmd.Execute(); err != nil {
log.Fatalf("executing error %+v", err)
}
}
func initRootCmd() (*cobra.Command, error) {
var fileName string
rootCmd := &cobra.Command{
Use: "scan2html",
Short: "A Trivy plugin that scans and outputs the results to a html file.",
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
RunE: func(cmd *cobra.Command, args []string) error {
return runPlugin(fileName)
},
}
rootCmd.PersistentFlags().StringVar(&fileName, "output", "trivy-report.html", "file to save html report")
return rootCmd, nil
}
func runPlugin(fileName string) error {
inputData, err := io.ReadAll(os.Stdin)
if err != nil {
return xerrors.Errorf("error reading trivy output: %w", err)
}
err = render.Render(fileName, inputData)
if err != nil {
return xerrors.Errorf("error rendering trivy output: %w", err)
}
return nil
}