// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. package global_init_scripts import ( "fmt" "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/flags" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/spf13/cobra" ) var Cmd = &cobra.Command{ Use: "global-init-scripts", Short: `The Global Init Scripts API enables Workspace administrators to configure global initialization scripts for their workspace.`, Long: `The Global Init Scripts API enables Workspace administrators to configure global initialization scripts for their workspace. These scripts run on every node in every cluster in the workspace. **Important:** Existing clusters must be restarted to pick up any changes made to global init scripts. Global init scripts are run in order. If the init script returns with a bad exit code, the Apache Spark container fails to launch and init scripts with later position are skipped. If enough containers fail, the entire cluster fails with a GLOBAL_INIT_SCRIPT_FAILURE error code.`, Annotations: map[string]string{ "package": "compute", }, } // start create command var createReq compute.GlobalInitScriptCreateRequest var createJson flags.JsonFlag func init() { Cmd.AddCommand(createCmd) // TODO: short flags createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) createCmd.Flags().BoolVar(&createReq.Enabled, "enabled", createReq.Enabled, `Specifies whether the script is enabled.`) createCmd.Flags().IntVar(&createReq.Position, "position", createReq.Position, `The position of a global init script, where 0 represents the first script to run, 1 is the second script to run, in ascending order.`) } var createCmd = &cobra.Command{ Use: "create NAME SCRIPT", Short: `Create init script.`, Long: `Create init script. Creates a new global init script in this workspace.`, Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) if cmd.Flags().Changed("json") { check = cobra.ExactArgs(0) } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { return err } } else { createReq.Name = args[0] createReq.Script = args[1] } response, err := w.GlobalInitScripts.Create(ctx, createReq) if err != nil { return err } return cmdio.Render(ctx, response) }, // Disable completions since they are not applicable. // Can be overridden by manual implementation in `override.go`. ValidArgsFunction: cobra.NoFileCompletions, } // start delete command var deleteReq compute.DeleteGlobalInitScriptRequest func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags } var deleteCmd = &cobra.Command{ Use: "delete SCRIPT_ID", Short: `Delete init script.`, Long: `Delete init script. Deletes a global init script.`, Annotations: map[string]string{}, PreRunE: root.MustWorkspaceClient, RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No SCRIPT_ID argument specified. Loading names for Global Init Scripts drop-down." names, err := w.GlobalInitScripts.GlobalInitScriptDetailsNameToScriptIdMap(ctx) close(promptSpinner) if err != nil { return fmt.Errorf("failed to load names for Global Init Scripts drop-down. Please manually specify required arguments. Original error: %w", err) } id, err := cmdio.Select(ctx, names, "The ID of the global init script") if err != nil { return err } args = append(args, id) } if len(args) != 1 { return fmt.Errorf("expected to have the id of the global init script") } deleteReq.ScriptId = args[0] err = w.GlobalInitScripts.Delete(ctx, deleteReq) if err != nil { return err } return nil }, // Disable completions since they are not applicable. // Can be overridden by manual implementation in `override.go`. ValidArgsFunction: cobra.NoFileCompletions, } // start get command var getReq compute.GetGlobalInitScriptRequest func init() { Cmd.AddCommand(getCmd) // TODO: short flags } var getCmd = &cobra.Command{ Use: "get SCRIPT_ID", Short: `Get an init script.`, Long: `Get an init script. Gets all the details of a script, including its Base64-encoded contents.`, Annotations: map[string]string{}, PreRunE: root.MustWorkspaceClient, RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No SCRIPT_ID argument specified. Loading names for Global Init Scripts drop-down." names, err := w.GlobalInitScripts.GlobalInitScriptDetailsNameToScriptIdMap(ctx) close(promptSpinner) if err != nil { return fmt.Errorf("failed to load names for Global Init Scripts drop-down. Please manually specify required arguments. Original error: %w", err) } id, err := cmdio.Select(ctx, names, "The ID of the global init script") if err != nil { return err } args = append(args, id) } if len(args) != 1 { return fmt.Errorf("expected to have the id of the global init script") } getReq.ScriptId = args[0] response, err := w.GlobalInitScripts.Get(ctx, getReq) if err != nil { return err } return cmdio.Render(ctx, response) }, // Disable completions since they are not applicable. // Can be overridden by manual implementation in `override.go`. ValidArgsFunction: cobra.NoFileCompletions, } // start list command func init() { Cmd.AddCommand(listCmd) } var listCmd = &cobra.Command{ Use: "list", Short: `Get init scripts.`, Long: `Get init scripts. Get a list of all global init scripts for this workspace. This returns all properties for each script but **not** the script contents. To retrieve the contents of a script, use the [get a global init script](#operation/get-script) operation.`, Annotations: map[string]string{}, PreRunE: root.MustWorkspaceClient, RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) response, err := w.GlobalInitScripts.ListAll(ctx) if err != nil { return err } return cmdio.Render(ctx, response) }, // Disable completions since they are not applicable. // Can be overridden by manual implementation in `override.go`. ValidArgsFunction: cobra.NoFileCompletions, } // start update command var updateReq compute.GlobalInitScriptUpdateRequest func init() { Cmd.AddCommand(updateCmd) // TODO: short flags updateCmd.Flags().BoolVar(&updateReq.Enabled, "enabled", updateReq.Enabled, `Specifies whether the script is enabled.`) updateCmd.Flags().IntVar(&updateReq.Position, "position", updateReq.Position, `The position of a script, where 0 represents the first script to run, 1 is the second script to run, in ascending order.`) } var updateCmd = &cobra.Command{ Use: "update NAME SCRIPT SCRIPT_ID", Short: `Update init script.`, Long: `Update init script. Updates a global init script, specifying only the fields to change. All fields are optional. Unspecified fields retain their current value.`, Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(3) return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) updateReq.Name = args[0] updateReq.Script = args[1] updateReq.ScriptId = args[2] err = w.GlobalInitScripts.Update(ctx, updateReq) if err != nil { return err } return nil }, // Disable completions since they are not applicable. // Can be overridden by manual implementation in `override.go`. ValidArgsFunction: cobra.NoFileCompletions, } // end service GlobalInitScripts