NewCloudShellManagerCommand creates a *cobra.Command object with default parameters
(ctx context.Context)
| 39 | |
| 40 | // NewCloudShellManagerCommand creates a *cobra.Command object with default parameters |
| 41 | func NewCloudShellManagerCommand(ctx context.Context) *cobra.Command { |
| 42 | opts, _ := options.NewOptions() |
| 43 | |
| 44 | cmd := &cobra.Command{ |
| 45 | Use: "cloudshell-manager", |
| 46 | Short: `Run this command in order to run cloudshell controller manager`, |
| 47 | RunE: func(cmd *cobra.Command, args []string) error { |
| 48 | verflag.PrintAndExitIfRequested() |
| 49 | |
| 50 | // Activate logging as soon as possible, after that |
| 51 | // show flags with the final logging configuration. |
| 52 | if err := logsv1.ValidateAndApply(opts.Logs, feature.FeatureGate); err != nil { |
| 53 | fmt.Fprintf(os.Stderr, "%v\n", err) |
| 54 | os.Exit(1) |
| 55 | } |
| 56 | cliflag.PrintFlags(cmd.Flags()) |
| 57 | |
| 58 | config, err := opts.Config() |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | |
| 63 | return Run(ctx, config) |
| 64 | }, |
| 65 | Args: func(cmd *cobra.Command, args []string) error { |
| 66 | for _, arg := range args { |
| 67 | if len(arg) > 0 { |
| 68 | return fmt.Errorf("%q does not take any arguments, got %q", cmd.CommandPath(), args) |
| 69 | } |
| 70 | } |
| 71 | return nil |
| 72 | }, |
| 73 | } |
| 74 | |
| 75 | namedFlagSets := opts.Flags() |
| 76 | verflag.AddFlags(namedFlagSets.FlagSet("global")) |
| 77 | globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name(), logs.SkipLoggingConfigurationFlags()) |
| 78 | |
| 79 | fs := cmd.Flags() |
| 80 | for _, f := range namedFlagSets.FlagSets { |
| 81 | fs.AddFlagSet(f) |
| 82 | } |
| 83 | |
| 84 | cols, _, _ := term.TerminalSize(cmd.OutOrStdout()) |
| 85 | cliflag.SetUsageAndHelpFunc(cmd, namedFlagSets, cols) |
| 86 | |
| 87 | return cmd |
| 88 | } |
| 89 | |
| 90 | func Run(ctx context.Context, config *config.Config) error { |
| 91 | // To help debugging, immediately log version |
no test coverage detected