MCPcopy Index your code
hub / github.com/bytebase/bytebase / NewRootCommand

Function NewRootCommand

action/command/root.go:20–44  ·  view source on GitHub ↗
(w *world.World)

Source from the content-addressed store, hash-verified

18)
19
20func 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
46func rootPreRun(w *world.World) func(cmd *cobra.Command, args []string) error {
47 return func(cmd *cobra.Command, _ []string) error {

Callers 2

executeActionCommandFunction · 0.92
mainFunction · 0.92

Calls 4

rootPreRunFunction · 0.85
newCustomHeaderFlagFunction · 0.85
NewCheckCommandFunction · 0.85
NewRolloutCommandFunction · 0.85

Tested by 1

executeActionCommandFunction · 0.74