forked from safedep/vet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
131 lines (109 loc) · 3.04 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"fmt"
"io"
"os"
"strconv"
"github.com/safedep/dry/utils"
"github.com/safedep/vet/cmd/cloud"
"github.com/safedep/vet/internal/ui"
"github.com/safedep/vet/pkg/common/logger"
"github.com/safedep/vet/pkg/exceptions"
"github.com/spf13/cobra"
)
var (
verbose bool
debug bool
noBanner bool
logFile string
globalExceptionsFile string
globalExceptionsExtra []string
)
var banner string = `
Yb dP 888888 888888
Yb dP 88__ 88
YbdP 88"" 88
YP 888888 88
`
func main() {
cmd := &cobra.Command{
Use: "vet [OPTIONS] COMMAND [ARG...]",
Short: "[ Establish trust in open source software supply chain ]",
TraverseChildren: true,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cmd.Help()
}
return fmt.Errorf("vet: %s is not a valid command", args[0])
},
}
cmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Show verbose logs")
cmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "Show debug logs")
cmd.PersistentFlags().BoolVarP(&noBanner, "no-banner", "", false, "Do not display the vet banner")
cmd.PersistentFlags().StringVarP(&logFile, "log", "l", "", "Write command logs to file, use - as for stdout")
cmd.PersistentFlags().StringVarP(&globalExceptionsFile, "exceptions", "e", "", "Load exceptions from file")
cmd.PersistentFlags().StringSliceVarP(&globalExceptionsExtra, "exceptions-extra", "", []string{}, "Load additional exceptions from file")
cmd.AddCommand(newAuthCommand())
cmd.AddCommand(newScanCommand())
cmd.AddCommand(newQueryCommand())
cmd.AddCommand(newCodeCommand())
cmd.AddCommand(newVersionCommand())
cmd.AddCommand(newConnectCommand())
cmd.AddCommand(cloud.NewCloudCommand())
cobra.OnInitialize(func() {
printBanner()
loadExceptions()
logger.SetLogLevel(verbose, debug)
})
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}
func loadExceptions() {
loadExceptionsFromFile(globalExceptionsFile)
for _, extra := range globalExceptionsExtra {
loadExceptionsFromFile(extra)
}
}
func loadExceptionsFromFile(file string) {
if file == "" {
return
}
loader, err := exceptions.NewExceptionsFileLoader(file)
if err != nil {
logger.Fatalf("Failed to create Exceptions loader: %v", err)
}
err = exceptions.Load(loader)
if err != nil {
logger.Fatalf("Failed to load exceptions: %v", err)
}
}
func printBanner() {
if noBanner {
return
}
bRet, err := strconv.ParseBool(os.Getenv("VET_DISABLE_BANNER"))
if (err == nil) && (bRet) {
return
}
ui.PrintBanner(banner)
}
// Redirect to file or discard log if empty
func redirectLogToFile(path string) {
logger.Debugf("Redirecting logger output to: %s", path)
if !utils.IsEmptyString(path) {
if path == "-" {
logger.MigrateTo(os.Stdout)
} else {
logger.LogToFile(path)
}
} else {
logger.MigrateTo(io.Discard)
}
}
func failOnError(stage string, err error) {
if err != nil {
ui.PrintError("%s failed due to error: %s", stage, err.Error())
os.Exit(-1)
}
}