-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
75 lines (64 loc) · 1.81 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
package main
import (
"fmt"
"os"
"runtime/debug"
"github.com/spf13/cobra"
"github.com/CrowdStrike/perseus/internal/server"
)
func main() {
// we pass the debugMode field on the package-level logLevel variable here to simplify the CLI
// argument management.
rootCommand.PersistentFlags().BoolVarP(&(logLevel.debugMode), "debug", "x", os.Getenv("LOG_VERBOSITY") == "debug", "enable verbose logging")
rootCommand.AddCommand(server.CreateServerCommand(logger))
rootCommand.AddCommand(createUpdateCommand())
rootCommand.AddCommand(createQueryCommand())
rootCommand.AddCommand(createFindPathsCommand())
rootCommand.AddCommand(versionCommand)
if err := rootCommand.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
}
var (
rootCommand = &cobra.Command{
Use: "perseus",
Short: "perseus - Defeating krakens since 2022",
SilenceErrors: true, // don't print errors, we're handling it in main()
SilenceUsage: true, // don't print usage on error
}
BuildDate = "unknown"
BuildVersion = "v0.0.0-dev"
commitHash = "unknown"
commitDate = "unknown"
versionInfoTemplate = `perseus - Defeating krakens since 2022
%s (built %s, %s %s/%s)
commit: %s (date: %s)
`
versionCommand = &cobra.Command{
Use: "version",
Short: "shows build/version info",
Run: runVersionCmd,
}
)
func runVersionCmd(_ *cobra.Command, _ []string) {
goos, goarch := "", ""
nfo, _ := debug.ReadBuildInfo()
for _, s := range nfo.Settings {
switch s.Key {
case "vcs.time":
commitDate = s.Value
case "vcs.revision":
commitHash = s.Value
case "GOOS":
goos = s.Value
case "GOARCH":
goarch = s.Value
default:
// don't care about other settings
}
}
fmt.Printf(versionInfoTemplate,
BuildVersion, BuildDate, nfo.GoVersion, goos, goarch,
commitHash, commitDate)
}