2023-09-05 09:43:57 +00:00
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package query_visualizations
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 : "query-visualizations" ,
2024-08-15 13:23:07 +00:00
Short : ` This is an evolving API that facilitates the addition and removal of visualizations from existing queries in the Databricks Workspace. ` ,
2023-09-05 09:43:57 +00:00
Long : ` This is an evolving API that facilitates the addition and removal of
2024-08-15 13:23:07 +00:00
visualizations from existing queries in the Databricks Workspace . Data
structures can change over time . ` ,
2023-09-05 09:43:57 +00:00
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 ,
2024-08-15 13:23:07 +00:00
* sql . CreateVisualizationRequest ,
2023-09-05 09:43:57 +00:00
)
func newCreate ( ) * cobra . Command {
cmd := & cobra . Command { }
2024-08-15 13:23:07 +00:00
var createReq sql . CreateVisualizationRequest
2023-09-05 09:43:57 +00:00
var createJson flags . JsonFlag
// TODO: short flags
cmd . Flags ( ) . Var ( & createJson , "json" , ` either inline JSON string or @path/to/file.json with request body ` )
2024-08-15 13:23:07 +00:00
// TODO: complex arg: visualization
2023-09-05 09:43:57 +00:00
cmd . Use = "create"
2024-08-15 13:23:07 +00:00
cmd . Short = ` Add a visualization to a query. `
cmd . Long = ` Add a visualization to a query .
Adds a visualization to a query . `
2023-09-05 09:43:57 +00:00
cmd . Annotations = make ( map [ string ] string )
2024-08-15 13:23:07 +00:00
cmd . Args = func ( cmd * cobra . Command , args [ ] string ) error {
check := root . ExactArgs ( 0 )
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 = 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
}
}
response , err := w . QueryVisualizations . 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 ,
2024-08-15 13:23:07 +00:00
* sql . DeleteVisualizationRequest ,
2023-09-05 09:43:57 +00:00
)
func newDelete ( ) * cobra . Command {
cmd := & cobra . Command { }
2024-08-15 13:23:07 +00:00
var deleteReq sql . DeleteVisualizationRequest
2023-09-05 09:43:57 +00:00
// TODO: short flags
cmd . Use = "delete ID"
2024-08-15 13:23:07 +00:00
cmd . Short = ` Remove a visualization. `
cmd . Long = ` Remove a visualization .
Removes a visualization . `
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 . QueryVisualizations . 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 ,
2024-08-15 13:23:07 +00:00
* sql . UpdateVisualizationRequest ,
2023-09-05 09:43:57 +00:00
)
func newUpdate ( ) * cobra . Command {
cmd := & cobra . Command { }
2024-08-15 13:23:07 +00:00
var updateReq sql . UpdateVisualizationRequest
2023-09-05 09:43:57 +00:00
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-08-15 13:23:07 +00:00
// TODO: complex arg: visualization
cmd . Use = "update ID UPDATE_MASK"
cmd . Short = ` Update a visualization. `
cmd . Long = ` Update a visualization .
Updates a visualization .
2024-01-17 14:14:20 +00:00
Arguments :
2024-08-15 13:23:07 +00:00
ID :
UPDATE_MASK : Field mask is required to be passed into the PATCH request . Field mask
specifies which fields of the setting payload will be updated . The field
mask needs to be supplied as single string . To specify multiple fields in
the field mask , use comma as the separator ( no space ) . `
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-08-15 13:23:07 +00:00
if cmd . Flags ( ) . Changed ( "json" ) {
err := root . ExactArgs ( 1 ) ( cmd , args )
if err != nil {
return fmt . Errorf ( "when --json flag is specified, provide only ID as positional arguments. Provide 'update_mask' in your JSON input" )
}
return nil
}
check := root . ExactArgs ( 2 )
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
}
}
2024-01-17 14:14:20 +00:00
updateReq . Id = args [ 0 ]
2024-08-15 13:23:07 +00:00
if ! cmd . Flags ( ) . Changed ( "json" ) {
updateReq . UpdateMask = args [ 1 ]
}
2023-09-05 09:43:57 +00:00
response , err := w . QueryVisualizations . 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 QueryVisualizations