2023-09-05 09:43:57 +00:00
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package dashboard_widgets
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/sql"
"github.com/spf13/cobra"
)
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var cmdOverrides [ ] func ( * cobra . Command )
func New ( ) * cobra . Command {
cmd := & cobra . Command {
Use : "dashboard-widgets" ,
Short : ` This is an evolving API that facilitates the addition and removal of widgets from existing dashboards within the Databricks Workspace. ` ,
Long : ` This is an evolving API that facilitates the addition and removal of widgets
from existing dashboards within the Databricks Workspace . Data structures may
change over time . ` ,
GroupID : "sql" ,
Annotations : map [ string ] string {
"package" : "sql" ,
} ,
// This service is being previewed; hide from help output.
Hidden : true ,
}
2024-03-06 09:53:44 +00:00
// Add methods
cmd . AddCommand ( newCreate ( ) )
cmd . AddCommand ( newDelete ( ) )
cmd . AddCommand ( newUpdate ( ) )
2023-09-05 09:43:57 +00:00
// Apply optional overrides to this command.
for _ , fn := range cmdOverrides {
fn ( cmd )
}
return cmd
}
// start create command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var createOverrides [ ] func (
* cobra . Command ,
* sql . CreateWidget ,
)
func newCreate ( ) * cobra . Command {
cmd := & cobra . Command { }
var createReq sql . CreateWidget
var createJson flags . JsonFlag
// TODO: short flags
cmd . Flags ( ) . Var ( & createJson , "json" , ` either inline JSON string or @path/to/file.json with request body ` )
cmd . Use = "create"
cmd . Short = ` Add widget to a dashboard. `
cmd . Long = ` Add widget to a dashboard. `
cmd . Annotations = make ( map [ string ] string )
cmd . PreRunE = root . MustWorkspaceClient
cmd . 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 {
2024-10-10 13:34:15 +00:00
return fmt . Errorf ( "failed to parse JSON string. Please ensure that the value provided to the --json flag is either a valid JSON string or @path/to/file.json with valid JSON content: %w" , err )
2023-09-05 09:43:57 +00:00
}
} else {
return fmt . Errorf ( "please provide command input in JSON format by specifying the --json flag" )
}
response , err := w . DashboardWidgets . 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`.
cmd . ValidArgsFunction = cobra . NoFileCompletions
// Apply optional overrides to this command.
for _ , fn := range createOverrides {
fn ( cmd , & createReq )
}
return cmd
}
// start delete command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var deleteOverrides [ ] func (
* cobra . Command ,
* sql . DeleteDashboardWidgetRequest ,
)
func newDelete ( ) * cobra . Command {
cmd := & cobra . Command { }
var deleteReq sql . DeleteDashboardWidgetRequest
// TODO: short flags
cmd . Use = "delete ID"
cmd . Short = ` Remove widget. `
2024-01-11 08:16:25 +00:00
cmd . Long = ` Remove widget .
Arguments :
ID : Widget ID returned by : method : dashboardwidgets / create `
2023-09-05 09:43:57 +00:00
cmd . Annotations = make ( map [ string ] string )
cmd . Args = func ( cmd * cobra . Command , args [ ] string ) error {
2024-03-12 14:12:34 +00:00
check := root . ExactArgs ( 1 )
2023-09-05 09:43:57 +00:00
return check ( cmd , args )
}
cmd . PreRunE = root . MustWorkspaceClient
cmd . RunE = func ( cmd * cobra . Command , args [ ] string ) ( err error ) {
ctx := cmd . Context ( )
w := root . WorkspaceClient ( ctx )
deleteReq . Id = args [ 0 ]
err = w . DashboardWidgets . 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`.
cmd . ValidArgsFunction = cobra . NoFileCompletions
// Apply optional overrides to this command.
for _ , fn := range deleteOverrides {
fn ( cmd , & deleteReq )
}
return cmd
}
// start update command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var updateOverrides [ ] func (
* cobra . Command ,
* sql . CreateWidget ,
)
func newUpdate ( ) * cobra . Command {
cmd := & cobra . Command { }
var updateReq sql . CreateWidget
var updateJson flags . JsonFlag
// TODO: short flags
cmd . Flags ( ) . Var ( & updateJson , "json" , ` either inline JSON string or @path/to/file.json with request body ` )
2024-01-17 14:14:20 +00:00
cmd . Use = "update ID"
2023-09-05 09:43:57 +00:00
cmd . Short = ` Update existing widget. `
2024-01-17 14:14:20 +00:00
cmd . Long = ` Update existing widget .
Arguments :
ID : Widget ID returned by : method : dashboardwidgets / create `
2023-09-05 09:43:57 +00:00
cmd . Annotations = make ( map [ string ] string )
2024-01-17 14:14:20 +00:00
cmd . Args = func ( cmd * cobra . Command , args [ ] string ) error {
2024-03-12 14:12:34 +00:00
check := root . ExactArgs ( 1 )
2024-01-17 14:14:20 +00:00
return check ( cmd , args )
}
2023-09-05 09:43:57 +00:00
cmd . PreRunE = root . MustWorkspaceClient
cmd . RunE = func ( cmd * cobra . Command , args [ ] string ) ( err error ) {
ctx := cmd . Context ( )
w := root . WorkspaceClient ( ctx )
if cmd . Flags ( ) . Changed ( "json" ) {
err = updateJson . Unmarshal ( & updateReq )
if err != nil {
2024-10-10 13:34:15 +00:00
return fmt . Errorf ( "failed to parse JSON string. Please ensure that the value provided to the --json flag is either a valid JSON string or @path/to/file.json with valid JSON content: %w" , err )
2023-09-05 09:43:57 +00:00
}
} else {
return fmt . Errorf ( "please provide command input in JSON format by specifying the --json flag" )
}
2024-01-17 14:14:20 +00:00
updateReq . Id = args [ 0 ]
2023-09-05 09:43:57 +00:00
response , err := w . DashboardWidgets . Update ( ctx , updateReq )
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`.
cmd . ValidArgsFunction = cobra . NoFileCompletions
// Apply optional overrides to this command.
for _ , fn := range updateOverrides {
fn ( cmd , & updateReq )
}
return cmd
}
// end service DashboardWidgets