| 18 | ) |
| 19 | |
| 20 | func NewRootCommand(w *world.World) *cobra.Command { |
| 21 | cmd := &cobra.Command{ |
| 22 | Use: "bytebase-action", |
| 23 | Short: "Bytebase action", |
| 24 | PersistentPreRunE: rootPreRun(w), |
| 25 | // XXX: PersistentPostRunE is not called when the command fails |
| 26 | // So we call it manually in the commands |
| 27 | } |
| 28 | // bytebase-action flags |
| 29 | cmd.PersistentFlags().StringVar(&w.Output, "output", "", "Output file location. The output file is a JSON file with the created resource names") |
| 30 | cmd.PersistentFlags().StringVar(&w.URL, "url", "", "Bytebase URL (required)") |
| 31 | cmd.PersistentFlags().DurationVar(&w.Timeout, "timeout", 120*time.Second, "HTTP timeout for API requests (e.g. 120s, 5m)") |
| 32 | cmd.PersistentFlags().StringVar(&w.ServiceAccount, "service-account", "", "Bytebase Service account") |
| 33 | cmd.PersistentFlags().StringVar(&w.ServiceAccountSecret, "service-account-secret", "", "Bytebase Service account secret") |
| 34 | cmd.PersistentFlags().StringVar(&w.AccessToken, "access-token", "", "Bytebase access token (alternative to service account auth, e.g. from workload identity exchange)") |
| 35 | cmd.PersistentFlags().Var(newCustomHeaderFlag(&w.CustomHeaders, &w.CustomHeaderError), "custom-header", "Custom HTTP header for Bytebase API requests, in 'Name: value' format. Can be specified multiple times") |
| 36 | cmd.PersistentFlags().StringVar(&w.Project, "project", "projects/hr", "Bytebase project") |
| 37 | cmd.PersistentFlags().StringSliceVar(&w.Targets, "targets", []string{"instances/test-sample-instance/databases/hr_test", "instances/prod-sample-instance/databases/hr_prod"}, "Bytebase targets. Either one or more databases or a single databaseGroup") |
| 38 | cmd.PersistentFlags().StringVar(&w.FilePattern, "file-pattern", "", "File pattern to glob migration files") |
| 39 | cmd.PersistentFlags().BoolVar(&w.Declarative, "declarative", false, "Whether to use declarative mode. (experimental)") |
| 40 | |
| 41 | cmd.AddCommand(NewCheckCommand(w)) |
| 42 | cmd.AddCommand(NewRolloutCommand(w)) |
| 43 | return cmd |
| 44 | } |
| 45 | |
| 46 | func rootPreRun(w *world.World) func(cmd *cobra.Command, args []string) error { |
| 47 | return func(cmd *cobra.Command, _ []string) error { |