-
Notifications
You must be signed in to change notification settings - Fork 68
/
main.go
69 lines (58 loc) · 1.4 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
package main
import (
"bytes"
goflag "flag"
"fmt"
"k8s.io/klog"
"os"
"github.com/alcideio/rbac-tool/cmd"
"github.com/spf13/cobra"
)
func RbacGenCmd() *cobra.Command {
var rootCmd = &cobra.Command{
Use: "rbac-tool",
Short: "rbac-tool",
Long: `rbac-tool`,
}
var genBashCompletionCmd = &cobra.Command{
Use: "bash-completion",
Short: "Generate bash completion. source <(rbac-tool bash-completion)",
Long: "Generate bash completion. source <(rbac-tool bash-completion)",
Run: func(cmd *cobra.Command, args []string) {
out := new(bytes.Buffer)
_ = rootCmd.GenBashCompletion(out)
fmt.Println(out.String())
},
}
cmds := []*cobra.Command{
cmd.NewCommandVersion(),
genBashCompletionCmd,
cmd.NewCommandGenerateClusterRole(),
cmd.NewCommandVisualize(),
cmd.NewCommandLookup(),
cmd.NewCommandPolicyRules(),
cmd.NewCommandAuditGen(),
cmd.NewCommandWhoCan(),
cmd.NewCommandAnalysis(),
cmd.NewCommandGenerateShowPermissions(),
cmd.NewCommandWhoAmI(),
}
flags := rootCmd.PersistentFlags()
klog.InitFlags(nil)
flags.AddGoFlagSet(goflag.CommandLine)
// Hide all klog flags except for -v
goflag.CommandLine.VisitAll(func(f *goflag.Flag) {
if f.Name != "v" {
flags.Lookup(f.Name).Hidden = true
}
})
rootCmd.AddCommand(cmds...)
return rootCmd
}
func main() {
rootCmd := RbacGenCmd()
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}