| 67 | } |
| 68 | |
| 69 | func NewCmd() *cobra.Command { |
| 70 | f := &flags.Flags{} |
| 71 | zapfs := flag.NewFlagSet("zap", flag.ExitOnError) |
| 72 | opts := &zapf.Options{} |
| 73 | opts.BindFlags(zapfs) |
| 74 | |
| 75 | cmd := &cobra.Command{ |
| 76 | Use: "run", |
| 77 | Short: "Run the operator", |
| 78 | Args: func(cmd *cobra.Command, _ []string) error { |
| 79 | if cmd.Flag("metrics-require-rbac").Value.String() == "true" && cmd.Flag("metrics-secure").Value.String() == "false" { |
| 80 | return errors.New("--metrics-secure flag is required when --metrics-require-rbac is present") |
| 81 | } |
| 82 | return nil |
| 83 | }, |
| 84 | Run: func(cmd *cobra.Command, _ []string) { |
| 85 | logf.SetLogger(zapf.New(zapf.UseFlagOptions(opts))) |
| 86 | run(cmd, f) |
| 87 | }, |
| 88 | } |
| 89 | |
| 90 | f.AddTo(cmd.Flags()) |
| 91 | cmd.Flags().AddGoFlagSet(zapfs) |
| 92 | return cmd |
| 93 | } |
| 94 | |
| 95 | func run(cmd *cobra.Command, f *flags.Flags) { |
| 96 | printVersion() |