-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathroot.go
63 lines (49 loc) · 1.64 KB
/
root.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
package cmd
import (
"flag"
"io"
"github.com/aquasecurity/starboard/pkg/starboard"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/cli-runtime/pkg/genericclioptions"
)
func NewRootCmd(buildInfo starboard.BuildInfo, args []string, outWriter io.Writer, errWriter io.Writer) *cobra.Command {
var cf *genericclioptions.ConfigFlags
rootCmd := &cobra.Command{
Use: "starboard",
Short: "Kubernetes-native security toolkit",
SilenceErrors: true,
SilenceUsage: true,
}
cf = genericclioptions.NewConfigFlags(true)
rootCmd.AddCommand(NewVersionCmd(buildInfo, outWriter))
rootCmd.AddCommand(NewInitCmd(cf))
rootCmd.AddCommand(NewFindCmd(buildInfo, cf))
rootCmd.AddCommand(NewScanCmd(buildInfo, cf))
rootCmd.AddCommand(NewKubeBenchCmd(cf))
rootCmd.AddCommand(NewKubeHunterCmd(cf))
rootCmd.AddCommand(NewPolarisCmd(buildInfo, cf))
rootCmd.AddCommand(NewGetCmd(buildInfo, cf, outWriter))
rootCmd.AddCommand(NewCleanupCmd(cf))
rootCmd.AddCommand(NewConfigCmd(cf, outWriter))
SetGlobalFlags(cf, rootCmd)
rootCmd.SetArgs(args[1:])
rootCmd.SetOut(outWriter)
rootCmd.SetErr(errWriter)
return rootCmd
}
// Run is the entry point of the Starboard CLI. It runs the specified
// command based on the specified args.
func Run(version starboard.BuildInfo, args []string, outWriter io.Writer, errWriter io.Writer) error {
initFlags()
return NewRootCmd(version, args, outWriter, errWriter).Execute()
}
func initFlags() {
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
// Hide all klog flags except for -v
flag.CommandLine.VisitAll(func(f *flag.Flag) {
if f.Name != "v" {
pflag.Lookup(f.Name).Hidden = true
}
})
}