Simplified code generation logic for handling path and request body parameters and JSON input (#905)

## Changes
Simplified code generation logic for handling path and request body
parameters and JSON input

Note: relies on these PRs: 
https://github.com/databricks/databricks-sdk-go/pull/666
https://github.com/databricks/databricks-sdk-go/pull/669
https://github.com/databricks/databricks-sdk-go/pull/670
This commit is contained in:
Andrew Nester 2023-10-24 19:37:08 +02:00 committed by GitHub
parent f8d7e31118
commit d768994bbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 452 additions and 700 deletions

View File

@ -78,12 +78,10 @@ var {{.CamelName}}Overrides []func(
func new{{.PascalName}}() *cobra.Command {
cmd := &cobra.Command{}
{{- $needJsonFlag := or .CanSetRequiredFieldsFromJson (and .Request (not .Request.IsOnlyPrimitiveFields)) -}}
{{- if .Request}}
var {{.CamelName}}Req {{.Service.Package.Name}}.{{.Request.PascalName}}
{{- if $needJsonFlag}}
{{- if .CanUseJson}}
var {{.CamelName}}Json flags.JsonFlag
{{- end}}
{{- end}}
@ -96,7 +94,7 @@ func new{{.PascalName}}() *cobra.Command {
cmd.Flags().DurationVar(&{{.CamelName}}Timeout, "timeout", {{.Wait.Timeout}}*time.Minute, `maximum amount of time to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state`)
{{end -}}
{{if .Request}}// TODO: short flags
{{- if $needJsonFlag}}
{{- if .CanUseJson}}
cmd.Flags().Var(&{{.CamelName}}Json, "json", `either inline JSON string or @path/to/file.json with request body`)
{{- end}}
{{$method := .}}
@ -120,12 +118,14 @@ func new{{.PascalName}}() *cobra.Command {
{{- $fullCommandName := (print $serviceName " " .KebabName) -}}
{{- $noPrompt := or .IsCrudCreate (in $excludeFromPrompts $fullCommandName) }}
{{- $hasPosArgs := and .Request (or .Request.IsAllRequiredFieldsPrimitive (eq .PascalName "RunNow")) -}}
{{- $hasPosArgs := and (not .MustUseJson) (and .Request (or .Request.IsAllRequiredFieldsPrimitive (eq .PascalName "RunNow"))) -}}
{{- $hasSinglePosArg := and $hasPosArgs (eq 1 (len .Request.RequiredFields)) -}}
{{- $serviceHasNamedIdMap := and (and .Service.List .Service.List.NamedIdMap) (not (eq .PascalName "List")) -}}
{{- $hasIdPrompt := and (not $noPrompt) (and $hasSinglePosArg $serviceHasNamedIdMap) -}}
{{- $wait := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}}
{{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}}
{{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}}
{{- $hasSingleRequiredRequestBodyFieldWithPrompt := and (and $hasIdPrompt .Request) (eq 1 (len .Request.RequiredRequestBodyFields)) -}}
cmd.Use = "{{.KebabName}}{{if $hasPosArgs}}{{range .Request.RequiredFields}} {{.ConstantName}}{{end}}{{end}}"
{{- if .Description }}
@ -142,9 +142,9 @@ func new{{.PascalName}}() *cobra.Command {
{{if $hasRequiredArgs }}
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs({{len .Request.RequiredFields}})
{{- if .CanSetRequiredFieldsFromJson }}
{{- if and .CanUseJson .Request.HasRequiredRequestBodyFields }}
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
check = cobra.ExactArgs({{len .Request.RequiredPathFields}})
}
{{- end }}
return check(cmd, args)
@ -155,14 +155,18 @@ func new{{.PascalName}}() *cobra.Command {
ctx := cmd.Context()
{{if .Service.IsAccounts}}a := root.AccountClient(ctx){{else}}w := root.WorkspaceClient(ctx){{end}}
{{- if .Request }}
{{ if $needJsonFlag }}
{{ if .CanUseJson }}
if cmd.Flags().Changed("json") {
err = {{.CamelName}}Json.Unmarshal(&{{.CamelName}}Req)
if err != nil {
return err
}
}{{end}}{{if .CanSetRequiredFieldsFromJson }} else {
{{- end }}
}{{end}}{{ if .MustUseJson }}else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}{{- end}}
{{- if (not .MustUseJson) }}
{{- if and .CanUseJson $hasSingleRequiredRequestBodyFieldWithPrompt }} else {
{{- end}}
{{- if $hasIdPrompt}}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
@ -182,22 +186,30 @@ func new{{.PascalName}}() *cobra.Command {
return fmt.Errorf("expected to have {{range .Request.RequiredFields}}{{.Summary | trimSuffix "." | lower}}{{end}}")
}
{{- end -}}
{{$method := .}}
{{- if and .Request.IsAllRequiredFieldsPrimitive (not .IsJsonOnly) -}}
{{- range $arg, $field := .Request.RequiredFields}}
{{if not $field.Entity.IsString -}}
_, err = fmt.Sscan(args[{{$arg}}], &{{$method.CamelName}}Req.{{$field.PascalName}})
if err != nil {
return fmt.Errorf("invalid {{$field.ConstantName}}: %s", args[{{$arg}}])
}{{else -}}
{{$method.CamelName}}Req.{{$field.PascalName}} = args[{{$arg}}]
{{- end -}}{{end}}
{{- else -}}
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
{{- range $arg, $field := .Request.RequiredFields}}
{{- $optionalIfJsonIsUsed := and (not $hasIdPrompt) (and $field.IsRequestBodyField $method.CanUseJson) }}
{{- if $optionalIfJsonIsUsed }}
if !cmd.Flags().Changed("json") {
{{- end }}
{{if not $field.Entity.IsString -}}
_, err = fmt.Sscan(args[{{$arg}}], &{{$method.CamelName}}Req.{{$field.PascalName}})
if err != nil {
return fmt.Errorf("invalid {{$field.ConstantName}}: %s", args[{{$arg}}])
}{{else -}}
{{$method.CamelName}}Req.{{$field.PascalName}} = args[{{$arg}}]
{{- end -}}
{{- if $optionalIfJsonIsUsed }}
}
{{- end }}
{{- end -}}
{{if .CanSetRequiredFieldsFromJson }}
{{- if and .CanUseJson $hasSingleRequiredRequestBodyFieldWithPrompt }}
}
{{end }}
{{- end}}
{{- end}}
{{end}}
{{if $wait -}}
wait, err := {{if .Service.IsAccounts}}a{{else}}w{{end}}.{{.Service.PascalName}}.{{.PascalName}}(ctx{{if .Request}}, {{.CamelName}}Req{{end}})

View File

@ -79,9 +79,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -95,7 +92,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := a.Groups.Create(ctx, createReq)
@ -282,10 +278,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq iam.ListAccountGroupsRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.Attributes, "attributes", listReq.Attributes, `Comma-separated list of attributes to return in response.`)
cmd.Flags().IntVar(&listReq.Count, "count", listReq.Count, `Desired number of results per page.`)
@ -305,9 +299,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -316,14 +307,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := a.Groups.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -147,9 +147,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -163,7 +160,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := a.LogDelivery.Create(ctx, createReq)
@ -278,10 +274,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq billing.ListLogDeliveryRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.CredentialsId, "credentials-id", listReq.CredentialsId, `Filter by credential configuration ID.`)
cmd.Flags().Var(&listReq.Status, "status", `Filter by status ENABLED or DISABLED.`)
@ -298,9 +292,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -309,14 +300,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := a.LogDelivery.ListAll(ctx, listReq)
if err != nil {
return err
@ -355,10 +338,12 @@ func newPatchStatus() *cobra.Command {
cmd := &cobra.Command{}
var patchStatusReq billing.UpdateLogDeliveryConfigurationStatusRequest
var patchStatusJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&patchStatusJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Use = "patch-status STATUS LOG_DELIVERY_CONFIGURATION_ID"
cmd.Use = "patch-status LOG_DELIVERY_CONFIGURATION_ID STATUS"
cmd.Short = `Enable or disable log delivery configuration.`
cmd.Long = `Enable or disable log delivery configuration.
@ -372,6 +357,9 @@ func newPatchStatus() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(1)
}
return check(cmd, args)
}
@ -380,11 +368,19 @@ func newPatchStatus() *cobra.Command {
ctx := cmd.Context()
a := root.AccountClient(ctx)
_, err = fmt.Sscan(args[0], &patchStatusReq.Status)
if err != nil {
return fmt.Errorf("invalid STATUS: %s", args[0])
if cmd.Flags().Changed("json") {
err = patchStatusJson.Unmarshal(&patchStatusReq)
if err != nil {
return err
}
}
patchStatusReq.LogDeliveryConfigurationId = args[0]
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[1], &patchStatusReq.Status)
if err != nil {
return fmt.Errorf("invalid STATUS: %s", args[1])
}
}
patchStatusReq.LogDeliveryConfigurationId = args[1]
err = a.LogDelivery.PatchStatus(ctx, patchStatusReq)
if err != nil {

View File

@ -64,9 +64,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -80,7 +77,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := a.Metastores.Create(ctx, createReq)

View File

@ -88,7 +88,8 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.NetworkName = args[0]
}

View File

@ -75,9 +75,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -91,7 +88,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
err = a.OAuthEnrollment.Create(ctx, createReq)

View File

@ -5,7 +5,6 @@ package o_auth_published_apps
import (
"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/oauth2"
"github.com/spf13/cobra"
)
@ -49,10 +48,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq oauth2.ListOAuthPublishedAppsRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().Int64Var(&listReq.PageSize, "page-size", listReq.PageSize, `The max number of OAuth published apps to return.`)
cmd.Flags().StringVar(&listReq.PageToken, "page-token", listReq.PageToken, `A token that can be used to get the next page of results.`)
@ -67,9 +64,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -78,14 +72,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := a.OAuthPublishedApps.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -97,8 +97,11 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.PrivateAccessSettingsName = args[0]
}
if !cmd.Flags().Changed("json") {
createReq.Region = args[1]
}
@ -358,7 +361,7 @@ func newReplace() *cobra.Command {
cmd.Flags().Var(&replaceReq.PrivateAccessLevel, "private-access-level", `The private access level controls which VPC endpoints can connect to the UI or API of any workspace that attaches this private access settings object.`)
cmd.Flags().BoolVar(&replaceReq.PublicAccessEnabled, "public-access-enabled", replaceReq.PublicAccessEnabled, `Determines if the workspace can be accessed over public internet.`)
cmd.Use = "replace PRIVATE_ACCESS_SETTINGS_NAME REGION PRIVATE_ACCESS_SETTINGS_ID"
cmd.Use = "replace PRIVATE_ACCESS_SETTINGS_ID PRIVATE_ACCESS_SETTINGS_NAME REGION"
cmd.Short = `Replace private access settings.`
cmd.Long = `Replace private access settings.
@ -388,6 +391,9 @@ func newReplace() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(1)
}
return check(cmd, args)
}
@ -402,9 +408,13 @@ func newReplace() *cobra.Command {
return err
}
}
replaceReq.PrivateAccessSettingsName = args[0]
replaceReq.Region = args[1]
replaceReq.PrivateAccessSettingsId = args[2]
replaceReq.PrivateAccessSettingsId = args[0]
if !cmd.Flags().Changed("json") {
replaceReq.PrivateAccessSettingsName = args[1]
}
if !cmd.Flags().Changed("json") {
replaceReq.Region = args[2]
}
err = a.PrivateAccess.Replace(ctx, replaceReq)
if err != nil {

View File

@ -69,9 +69,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -85,7 +82,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := a.PublishedAppIntegration.Create(ctx, createReq)

View File

@ -77,9 +77,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -93,7 +90,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := a.ServicePrincipals.Create(ctx, createReq)
@ -281,10 +277,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq iam.ListAccountServicePrincipalsRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.Attributes, "attributes", listReq.Attributes, `Comma-separated list of attributes to return in response.`)
cmd.Flags().IntVar(&listReq.Count, "count", listReq.Count, `Desired number of results per page.`)
@ -304,9 +298,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -315,14 +306,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := a.ServicePrincipals.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -197,9 +197,6 @@ func newUpdatePersonalComputeSetting() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -213,7 +210,6 @@ func newUpdatePersonalComputeSetting() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := a.Settings.UpdatePersonalComputeSetting(ctx, updatePersonalComputeSettingReq)

View File

@ -85,9 +85,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -101,7 +98,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := a.Users.Create(ctx, createReq)
@ -289,10 +285,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq iam.ListAccountUsersRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.Attributes, "attributes", listReq.Attributes, `Comma-separated list of attributes to return in response.`)
cmd.Flags().IntVar(&listReq.Count, "count", listReq.Count, `Desired number of results per page.`)
@ -312,9 +306,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -323,14 +314,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := a.Users.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -95,7 +95,8 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.VpcEndpointName = args[0]
}

View File

@ -116,7 +116,8 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.WorkspaceName = args[0]
}

View File

@ -93,7 +93,8 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}

View File

@ -250,10 +250,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq sharing.ListCleanRoomsRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().IntVar(&listReq.MaxResults, "max-results", listReq.MaxResults, `Maximum number of clean rooms to return.`)
cmd.Flags().StringVar(&listReq.PageToken, "page-token", listReq.PageToken, `Pagination token to go to next page based on previous query.`)
@ -270,9 +268,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -281,14 +276,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.CleanRooms.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -108,7 +108,8 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}
@ -271,8 +272,11 @@ func newEdit() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
editReq.PolicyId = args[0]
}
if !cmd.Flags().Changed("json") {
editReq.Name = args[1]
}
@ -534,10 +538,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq compute.ListClusterPoliciesRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().Var(&listReq.SortColumn, "sort-column", `The cluster policy attribute to sort by.`)
cmd.Flags().Var(&listReq.SortOrder, "sort-order", `The order in which the policies get listed.`)
@ -552,9 +554,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -563,14 +562,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.ClusterPolicies.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -107,8 +107,11 @@ func newChangeOwner() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
changeOwnerReq.ClusterId = args[0]
}
if !cmd.Flags().Changed("json") {
changeOwnerReq.OwnerUsername = args[1]
}
@ -221,7 +224,8 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.SparkVersion = args[0]
}
@ -452,8 +456,11 @@ func newEdit() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
editReq.ClusterId = args[0]
}
if !cmd.Flags().Changed("json") {
editReq.SparkVersion = args[1]
}
@ -824,10 +831,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq compute.ListClustersRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.CanUseClient, "can-use-client", listReq.CanUseClient, `Filter clusters based on what type of client it can be used for.`)
@ -849,9 +854,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -860,14 +862,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.Clusters.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -58,20 +58,12 @@ func newCreate() *cobra.Command {
// TODO: short flags
cmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Use = "create NAME"
cmd.Use = "create"
cmd.Short = `Create a dashboard object.`
cmd.Long = `Create a dashboard object.`
cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
@ -272,10 +264,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq sql.ListDashboardsRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().Var(&listReq.Order, "order", `Name of dashboard attribute to order by.`)
cmd.Flags().IntVar(&listReq.Page, "page", listReq.Page, `Page number to retrieve.`)
@ -292,9 +282,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -303,14 +290,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.Dashboards.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -95,7 +95,8 @@ func newCreateExperiment() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createExperimentReq.Name = args[0]
}
@ -160,9 +161,6 @@ func newCreateRun() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -176,7 +174,6 @@ func newCreateRun() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.Experiments.CreateRun(ctx, createRunReq)
@ -250,7 +247,8 @@ func newDeleteExperiment() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
deleteExperimentReq.ExperimentId = args[0]
}
@ -323,7 +321,8 @@ func newDeleteRun() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
deleteRunReq.RunId = args[0]
}
@ -399,8 +398,11 @@ func newDeleteRuns() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
deleteRunsReq.ExperimentId = args[0]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[1], &deleteRunsReq.MaxTimestampMillis)
if err != nil {
return fmt.Errorf("invalid MAX_TIMESTAMP_MILLIS: %s", args[1])
@ -477,8 +479,11 @@ func newDeleteTag() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
deleteTagReq.RunId = args[0]
}
if !cmd.Flags().Changed("json") {
deleteTagReq.Key = args[1]
}
@ -907,10 +912,8 @@ func newListArtifacts() *cobra.Command {
cmd := &cobra.Command{}
var listArtifactsReq ml.ListArtifactsRequest
var listArtifactsJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listArtifactsJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listArtifactsReq.PageToken, "page-token", listArtifactsReq.PageToken, `Token indicating the page of artifact results to fetch.`)
cmd.Flags().StringVar(&listArtifactsReq.Path, "path", listArtifactsReq.Path, `Filter artifacts matching this path (a relative path from the root artifact directory).`)
@ -928,9 +931,6 @@ func newListArtifacts() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -939,14 +939,6 @@ func newListArtifacts() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listArtifactsJson.Unmarshal(&listArtifactsReq)
if err != nil {
return err
}
} else {
}
response, err := w.Experiments.ListArtifactsAll(ctx, listArtifactsReq)
if err != nil {
return err
@ -985,10 +977,8 @@ func newListExperiments() *cobra.Command {
cmd := &cobra.Command{}
var listExperimentsReq ml.ListExperimentsRequest
var listExperimentsJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listExperimentsJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().IntVar(&listExperimentsReq.MaxResults, "max-results", listExperimentsReq.MaxResults, `Maximum number of experiments desired.`)
cmd.Flags().StringVar(&listExperimentsReq.PageToken, "page-token", listExperimentsReq.PageToken, `Token indicating the page of experiments to fetch.`)
@ -1004,9 +994,6 @@ func newListExperiments() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1015,14 +1002,6 @@ func newListExperiments() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listExperimentsJson.Unmarshal(&listExperimentsReq)
if err != nil {
return err
}
} else {
}
response, err := w.Experiments.ListExperimentsAll(ctx, listExperimentsReq)
if err != nil {
return err
@ -1117,9 +1096,6 @@ func newLogBatch() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1133,7 +1109,6 @@ func newLogBatch() *cobra.Command {
if err != nil {
return err
}
} else {
}
err = w.Experiments.LogBatch(ctx, logBatchReq)
@ -1193,9 +1168,6 @@ func newLogInputs() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1209,7 +1181,6 @@ func newLogInputs() *cobra.Command {
if err != nil {
return err
}
} else {
}
err = w.Experiments.LogInputs(ctx, logInputsReq)
@ -1287,12 +1258,17 @@ func newLogMetric() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
logMetricReq.Key = args[0]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[1], &logMetricReq.Value)
if err != nil {
return fmt.Errorf("invalid VALUE: %s", args[1])
}
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[2], &logMetricReq.Timestamp)
if err != nil {
return fmt.Errorf("invalid TIMESTAMP: %s", args[2])
@ -1356,9 +1332,6 @@ func newLogModel() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1372,7 +1345,6 @@ func newLogModel() *cobra.Command {
if err != nil {
return err
}
} else {
}
err = w.Experiments.LogModel(ctx, logModelReq)
@ -1450,8 +1422,11 @@ func newLogParam() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
logParamReq.Key = args[0]
}
if !cmd.Flags().Changed("json") {
logParamReq.Value = args[1]
}
@ -1529,7 +1504,8 @@ func newRestoreExperiment() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
restoreExperimentReq.ExperimentId = args[0]
}
@ -1602,7 +1578,8 @@ func newRestoreRun() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
restoreRunReq.RunId = args[0]
}
@ -1678,8 +1655,11 @@ func newRestoreRuns() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
restoreRunsReq.ExperimentId = args[0]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[1], &restoreRunsReq.MinTimestampMillis)
if err != nil {
return fmt.Errorf("invalid MIN_TIMESTAMP_MILLIS: %s", args[1])
@ -1745,9 +1725,6 @@ func newSearchExperiments() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1761,7 +1738,6 @@ func newSearchExperiments() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.Experiments.SearchExperimentsAll(ctx, searchExperimentsReq)
@ -1826,9 +1802,6 @@ func newSearchRuns() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1842,7 +1815,6 @@ func newSearchRuns() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.Experiments.SearchRunsAll(ctx, searchRunsReq)
@ -1914,9 +1886,14 @@ func newSetExperimentTag() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
setExperimentTagReq.ExperimentId = args[0]
}
if !cmd.Flags().Changed("json") {
setExperimentTagReq.Key = args[1]
}
if !cmd.Flags().Changed("json") {
setExperimentTagReq.Value = args[2]
}
@ -2065,8 +2042,11 @@ func newSetTag() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
setTagReq.Key = args[0]
}
if !cmd.Flags().Changed("json") {
setTagReq.Value = args[1]
}
@ -2141,7 +2121,8 @@ func newUpdateExperiment() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
updateExperimentReq.ExperimentId = args[0]
}
@ -2275,9 +2256,6 @@ func newUpdateRun() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -2291,7 +2269,6 @@ func newUpdateRun() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.Experiments.UpdateRun(ctx, updateRunReq)

View File

@ -97,9 +97,14 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
createReq.Url = args[1]
}
if !cmd.Flags().Changed("json") {
createReq.CredentialName = args[2]
}

View File

@ -355,8 +355,10 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{}
var updateReq catalog.UpdateFunction
var updateJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateReq.Owner, "owner", updateReq.Owner, `Username of current owner of function.`)
@ -380,6 +382,12 @@ func newUpdate() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = updateJson.Unmarshal(&updateReq)
if err != nil {
return err
}
}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No NAME argument specified. Loading names for Functions drop-down."

View File

@ -90,7 +90,8 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.GitProvider = args[0]
}
@ -333,8 +334,10 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{}
var updateReq workspace.UpdateCredentials
var updateJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateReq.GitProvider, "git-provider", updateReq.GitProvider, `Git provider.`)
cmd.Flags().StringVar(&updateReq.GitUsername, "git-username", updateReq.GitUsername, `Git username.`)
@ -353,6 +356,12 @@ func newUpdate() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = updateJson.Unmarshal(&updateReq)
if err != nil {
return err
}
}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No CREDENTIAL_ID argument specified. Loading names for Git Credentials drop-down."

View File

@ -90,8 +90,11 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
createReq.Script = args[1]
}
@ -330,13 +333,15 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{}
var updateReq compute.GlobalInitScriptUpdateRequest
var updateJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().BoolVar(&updateReq.Enabled, "enabled", updateReq.Enabled, `Specifies whether the script is enabled.`)
cmd.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.`)
cmd.Use = "update NAME SCRIPT SCRIPT_ID"
cmd.Use = "update SCRIPT_ID NAME SCRIPT"
cmd.Short = `Update init script.`
cmd.Long = `Update init script.
@ -347,6 +352,9 @@ func newUpdate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(1)
}
return check(cmd, args)
}
@ -355,9 +363,19 @@ func newUpdate() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
updateReq.Name = args[0]
updateReq.Script = args[1]
updateReq.ScriptId = args[2]
if cmd.Flags().Changed("json") {
err = updateJson.Unmarshal(&updateReq)
if err != nil {
return err
}
}
updateReq.ScriptId = args[0]
if !cmd.Flags().Changed("json") {
updateReq.Name = args[1]
}
if !cmd.Flags().Changed("json") {
updateReq.Script = args[2]
}
err = w.GlobalInitScripts.Update(ctx, updateReq)
if err != nil {

View File

@ -79,9 +79,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -95,7 +92,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.Groups.Create(ctx, createReq)
@ -282,10 +278,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq iam.ListGroupsRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.Attributes, "attributes", listReq.Attributes, `Comma-separated list of attributes to return in response.`)
cmd.Flags().IntVar(&listReq.Count, "count", listReq.Count, `Desired number of results per page.`)
@ -305,9 +299,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -316,14 +307,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.Groups.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -108,8 +108,11 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.InstancePoolName = args[0]
}
if !cmd.Flags().Changed("json") {
createReq.NodeTypeId = args[1]
}
@ -270,9 +273,14 @@ func newEdit() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
editReq.InstancePoolId = args[0]
}
if !cmd.Flags().Changed("json") {
editReq.InstancePoolName = args[1]
}
if !cmd.Flags().Changed("json") {
editReq.NodeTypeId = args[2]
}

View File

@ -87,7 +87,8 @@ func newAdd() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
addReq.InstanceProfileArn = args[0]
}
@ -177,7 +178,8 @@ func newEdit() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
editReq.InstanceProfileArn = args[0]
}
@ -303,7 +305,8 @@ func newRemove() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
removeReq.InstanceProfileArn = args[0]
}

View File

@ -85,9 +85,6 @@ func newCancelAllRuns() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -101,7 +98,6 @@ func newCancelAllRuns() *cobra.Command {
if err != nil {
return err
}
} else {
}
err = w.Jobs.CancelAllRuns(ctx, cancelAllRunsReq)
@ -265,14 +261,6 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
@ -964,10 +952,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq jobs.ListJobsRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().BoolVar(&listReq.ExpandTasks, "expand-tasks", listReq.ExpandTasks, `Whether to include task and cluster details in the response.`)
cmd.Flags().IntVar(&listReq.Limit, "limit", listReq.Limit, `The number of jobs to return.`)
@ -985,9 +971,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -996,14 +979,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.Jobs.ListAll(ctx, listReq)
if err != nil {
return err
@ -1042,10 +1017,8 @@ func newListRuns() *cobra.Command {
cmd := &cobra.Command{}
var listRunsReq jobs.ListRunsRequest
var listRunsJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listRunsJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().BoolVar(&listRunsReq.ActiveOnly, "active-only", listRunsReq.ActiveOnly, `If active_only is true, only active runs are included in the results; otherwise, lists both active and completed runs.`)
cmd.Flags().BoolVar(&listRunsReq.CompletedOnly, "completed-only", listRunsReq.CompletedOnly, `If completed_only is true, only completed runs are included in the results; otherwise, lists both active and completed runs.`)
@ -1068,9 +1041,6 @@ func newListRuns() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1079,14 +1049,6 @@ func newListRuns() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listRunsJson.Unmarshal(&listRunsReq)
if err != nil {
return err
}
} else {
}
response, err := w.Jobs.ListRunsAll(ctx, listRunsReq)
if err != nil {
return err
@ -1556,9 +1518,6 @@ func newSubmit() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1572,7 +1531,6 @@ func newSubmit() *cobra.Command {
if err != nil {
return err
}
} else {
}
wait, err := w.Jobs.Submit(ctx, submitReq)

View File

@ -60,10 +60,12 @@ func newAssign() *cobra.Command {
cmd := &cobra.Command{}
var assignReq catalog.CreateMetastoreAssignment
var assignJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&assignJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Use = "assign METASTORE_ID DEFAULT_CATALOG_NAME WORKSPACE_ID"
cmd.Use = "assign WORKSPACE_ID METASTORE_ID DEFAULT_CATALOG_NAME"
cmd.Short = `Create an assignment.`
cmd.Long = `Create an assignment.
@ -75,6 +77,9 @@ func newAssign() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(1)
}
return check(cmd, args)
}
@ -83,11 +88,21 @@ func newAssign() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
assignReq.MetastoreId = args[0]
assignReq.DefaultCatalogName = args[1]
_, err = fmt.Sscan(args[2], &assignReq.WorkspaceId)
if cmd.Flags().Changed("json") {
err = assignJson.Unmarshal(&assignReq)
if err != nil {
return err
}
}
_, err = fmt.Sscan(args[0], &assignReq.WorkspaceId)
if err != nil {
return fmt.Errorf("invalid WORKSPACE_ID: %s", args[2])
return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0])
}
if !cmd.Flags().Changed("json") {
assignReq.MetastoreId = args[1]
}
if !cmd.Flags().Changed("json") {
assignReq.DefaultCatalogName = args[2]
}
err = w.Metastores.Assign(ctx, assignReq)
@ -161,8 +176,11 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
createReq.StorageRoot = args[1]
}
@ -361,8 +379,11 @@ func newEnableOptimization() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
enableOptimizationReq.MetastoreId = args[0]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[1], &enableOptimizationReq.Enable)
if err != nil {
return fmt.Errorf("invalid ENABLE: %s", args[1])
@ -645,8 +666,10 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{}
var updateReq catalog.UpdateMetastore
var updateJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateReq.DeltaSharingOrganizationName, "delta-sharing-organization-name", updateReq.DeltaSharingOrganizationName, `The organization name of a Delta Sharing entity, to be used in Databricks-to-Databricks Delta Sharing as the official name.`)
cmd.Flags().Int64Var(&updateReq.DeltaSharingRecipientTokenLifetimeInSeconds, "delta-sharing-recipient-token-lifetime-in-seconds", updateReq.DeltaSharingRecipientTokenLifetimeInSeconds, `The lifetime of delta sharing recipient token in seconds.`)
@ -670,6 +693,12 @@ func newUpdate() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = updateJson.Unmarshal(&updateReq)
if err != nil {
return err
}
}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down."
@ -727,8 +756,10 @@ func newUpdateAssignment() *cobra.Command {
cmd := &cobra.Command{}
var updateAssignmentReq catalog.UpdateMetastoreAssignment
var updateAssignmentJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&updateAssignmentJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateAssignmentReq.DefaultCatalogName, "default-catalog-name", updateAssignmentReq.DefaultCatalogName, `The name of the default catalog for the metastore.`)
cmd.Flags().StringVar(&updateAssignmentReq.MetastoreId, "metastore-id", updateAssignmentReq.MetastoreId, `The unique ID of the metastore.`)
@ -749,6 +780,12 @@ func newUpdateAssignment() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = updateAssignmentJson.Unmarshal(&updateAssignmentReq)
if err != nil {
return err
}
}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Metastores drop-down."

View File

@ -82,13 +82,20 @@ func newApproveTransitionRequest() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
approveTransitionRequestReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
approveTransitionRequestReq.Version = args[1]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[2], &approveTransitionRequestReq.Stage)
if err != nil {
return fmt.Errorf("invalid STAGE: %s", args[2])
}
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[3], &approveTransitionRequestReq.ArchiveExistingVersions)
if err != nil {
return fmt.Errorf("invalid ARCHIVE_EXISTING_VERSIONS: %s", args[3])
@ -166,9 +173,14 @@ func newCreateComment() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createCommentReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
createCommentReq.Version = args[1]
}
if !cmd.Flags().Changed("json") {
createCommentReq.Comment = args[2]
}
@ -247,7 +259,8 @@ func newCreateModel() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createModelReq.Name = args[0]
}
@ -325,8 +338,11 @@ func newCreateModelVersion() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createModelVersionReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
createModelVersionReq.Source = args[1]
}
@ -401,9 +417,14 @@ func newCreateTransitionRequest() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createTransitionRequestReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
createTransitionRequestReq.Version = args[1]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[2], &createTransitionRequestReq.Stage)
if err != nil {
return fmt.Errorf("invalid STAGE: %s", args[2])
@ -899,10 +920,8 @@ func newDeleteWebhook() *cobra.Command {
cmd := &cobra.Command{}
var deleteWebhookReq ml.DeleteWebhookRequest
var deleteWebhookJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&deleteWebhookJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&deleteWebhookReq.Id, "id", deleteWebhookReq.Id, `Webhook ID required to delete a registry webhook.`)
@ -918,9 +937,6 @@ func newDeleteWebhook() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -929,14 +945,6 @@ func newDeleteWebhook() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = deleteWebhookJson.Unmarshal(&deleteWebhookReq)
if err != nil {
return err
}
} else {
}
err = w.ModelRegistry.DeleteWebhook(ctx, deleteWebhookReq)
if err != nil {
return err
@ -1008,7 +1016,8 @@ func newGetLatestVersions() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
getLatestVersionsReq.Name = args[0]
}
@ -1362,10 +1371,8 @@ func newListModels() *cobra.Command {
cmd := &cobra.Command{}
var listModelsReq ml.ListModelsRequest
var listModelsJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listModelsJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().IntVar(&listModelsReq.MaxResults, "max-results", listModelsReq.MaxResults, `Maximum number of registered models desired.`)
cmd.Flags().StringVar(&listModelsReq.PageToken, "page-token", listModelsReq.PageToken, `Pagination token to go to the next page based on a previous query.`)
@ -1381,9 +1388,6 @@ func newListModels() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1392,14 +1396,6 @@ func newListModels() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listModelsJson.Unmarshal(&listModelsReq)
if err != nil {
return err
}
} else {
}
response, err := w.ModelRegistry.ListModelsAll(ctx, listModelsReq)
if err != nil {
return err
@ -1500,10 +1496,8 @@ func newListWebhooks() *cobra.Command {
cmd := &cobra.Command{}
var listWebhooksReq ml.ListWebhooksRequest
var listWebhooksJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listWebhooksJson, "json", `either inline JSON string or @path/to/file.json with request body`)
// TODO: array: events
cmd.Flags().StringVar(&listWebhooksReq.ModelName, "model-name", listWebhooksReq.ModelName, `If not specified, all webhooks associated with the specified events are listed, regardless of their associated model.`)
@ -1521,9 +1515,6 @@ func newListWebhooks() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1532,14 +1523,6 @@ func newListWebhooks() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listWebhooksJson.Unmarshal(&listWebhooksReq)
if err != nil {
return err
}
} else {
}
response, err := w.ModelRegistry.ListWebhooksAll(ctx, listWebhooksReq)
if err != nil {
return err
@ -1611,9 +1594,14 @@ func newRejectTransitionRequest() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
rejectTransitionRequestReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
rejectTransitionRequestReq.Version = args[1]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[2], &rejectTransitionRequestReq.Stage)
if err != nil {
return fmt.Errorf("invalid STAGE: %s", args[2])
@ -1691,7 +1679,8 @@ func newRenameModel() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
renameModelReq.Name = args[0]
}
@ -1733,10 +1722,8 @@ func newSearchModelVersions() *cobra.Command {
cmd := &cobra.Command{}
var searchModelVersionsReq ml.SearchModelVersionsRequest
var searchModelVersionsJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&searchModelVersionsJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&searchModelVersionsReq.Filter, "filter", searchModelVersionsReq.Filter, `String filter condition, like "name='my-model-name'".`)
cmd.Flags().IntVar(&searchModelVersionsReq.MaxResults, "max-results", searchModelVersionsReq.MaxResults, `Maximum number of models desired.`)
@ -1753,9 +1740,6 @@ func newSearchModelVersions() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1764,14 +1748,6 @@ func newSearchModelVersions() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = searchModelVersionsJson.Unmarshal(&searchModelVersionsReq)
if err != nil {
return err
}
} else {
}
response, err := w.ModelRegistry.SearchModelVersionsAll(ctx, searchModelVersionsReq)
if err != nil {
return err
@ -1810,10 +1786,8 @@ func newSearchModels() *cobra.Command {
cmd := &cobra.Command{}
var searchModelsReq ml.SearchModelsRequest
var searchModelsJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&searchModelsJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&searchModelsReq.Filter, "filter", searchModelsReq.Filter, `String filter condition, like "name LIKE 'my-model-name'".`)
cmd.Flags().IntVar(&searchModelsReq.MaxResults, "max-results", searchModelsReq.MaxResults, `Maximum number of models desired.`)
@ -1830,9 +1804,6 @@ func newSearchModels() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -1841,14 +1812,6 @@ func newSearchModels() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = searchModelsJson.Unmarshal(&searchModelsReq)
if err != nil {
return err
}
} else {
}
response, err := w.ModelRegistry.SearchModelsAll(ctx, searchModelsReq)
if err != nil {
return err
@ -1918,9 +1881,14 @@ func newSetModelTag() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
setModelTagReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
setModelTagReq.Key = args[1]
}
if !cmd.Flags().Changed("json") {
setModelTagReq.Value = args[2]
}
@ -1993,10 +1961,17 @@ func newSetModelVersionTag() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
setModelVersionTagReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
setModelVersionTagReq.Version = args[1]
}
if !cmd.Flags().Changed("json") {
setModelVersionTagReq.Key = args[2]
}
if !cmd.Flags().Changed("json") {
setModelVersionTagReq.Value = args[3]
}
@ -2145,7 +2120,8 @@ func newTestRegistryWebhook() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
testRegistryWebhookReq.Id = args[0]
}
@ -2224,13 +2200,20 @@ func newTransitionStage() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
transitionStageReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
transitionStageReq.Version = args[1]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[2], &transitionStageReq.Stage)
if err != nil {
return fmt.Errorf("invalid STAGE: %s", args[2])
}
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[3], &transitionStageReq.ArchiveExistingVersions)
if err != nil {
return fmt.Errorf("invalid ARCHIVE_EXISTING_VERSIONS: %s", args[3])
@ -2306,8 +2289,11 @@ func newUpdateComment() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
updateCommentReq.Id = args[0]
}
if !cmd.Flags().Changed("json") {
updateCommentReq.Comment = args[1]
}
@ -2382,7 +2368,8 @@ func newUpdateModel() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
updateModelReq.Name = args[0]
}
@ -2457,8 +2444,11 @@ func newUpdateModelVersion() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
updateModelVersionReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
updateModelVersionReq.Version = args[1]
}
@ -2611,7 +2601,8 @@ func newUpdateWebhook() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
updateWebhookReq.Id = args[0]
}

View File

@ -7,6 +7,7 @@ import (
"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/catalog"
"github.com/spf13/cobra"
)
@ -336,8 +337,10 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{}
var updateReq catalog.UpdateModelVersionRequest
var updateJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateReq.Comment, "comment", updateReq.Comment, `The comment attached to the model version.`)
@ -366,6 +369,12 @@ func newUpdate() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = updateJson.Unmarshal(&updateReq)
if err != nil {
return err
}
}
updateReq.FullName = args[0]
_, err = fmt.Sscan(args[1], &updateReq.Version)
if err != nil {

View File

@ -76,14 +76,6 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
@ -494,10 +486,8 @@ func newListPipelineEvents() *cobra.Command {
cmd := &cobra.Command{}
var listPipelineEventsReq pipelines.ListPipelineEventsRequest
var listPipelineEventsJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listPipelineEventsJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listPipelineEventsReq.Filter, "filter", listPipelineEventsReq.Filter, `Criteria to select a subset of results, expressed using a SQL-like syntax.`)
cmd.Flags().IntVar(&listPipelineEventsReq.MaxResults, "max-results", listPipelineEventsReq.MaxResults, `Max number of entries to return in a single page.`)
@ -517,12 +507,6 @@ func newListPipelineEvents() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listPipelineEventsJson.Unmarshal(&listPipelineEventsReq)
if err != nil {
return err
}
}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down."
@ -580,10 +564,8 @@ func newListPipelines() *cobra.Command {
cmd := &cobra.Command{}
var listPipelinesReq pipelines.ListPipelinesRequest
var listPipelinesJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listPipelinesJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listPipelinesReq.Filter, "filter", listPipelinesReq.Filter, `Select a subset of results based on the specified criteria.`)
cmd.Flags().IntVar(&listPipelinesReq.MaxResults, "max-results", listPipelinesReq.MaxResults, `The maximum number of entries to return in a single page.`)
@ -600,9 +582,6 @@ func newListPipelines() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -611,14 +590,6 @@ func newListPipelines() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listPipelinesJson.Unmarshal(&listPipelinesReq)
if err != nil {
return err
}
} else {
}
response, err := w.Pipelines.ListPipelinesAll(ctx, listPipelinesReq)
if err != nil {
return err

View File

@ -5,7 +5,6 @@ package policy_families
import (
"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"
)
@ -115,10 +114,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq compute.ListPolicyFamiliesRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().Int64Var(&listReq.MaxResults, "max-results", listReq.MaxResults, `The max number of policy families to return.`)
cmd.Flags().StringVar(&listReq.PageToken, "page-token", listReq.PageToken, `A token that can be used to get the next page of results.`)
@ -133,9 +130,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -144,14 +138,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.PolicyFamilies.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -85,8 +85,11 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[1], &createReq.AuthenticationType)
if err != nil {
return fmt.Errorf("invalid AUTHENTICATION_TYPE: %s", args[1])
@ -280,10 +283,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq sharing.ListProvidersRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.DataProviderGlobalMetastoreId, "data-provider-global-metastore-id", listReq.DataProviderGlobalMetastoreId, `If not provided, all providers will be returned.`)
@ -300,9 +301,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -311,14 +309,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.Providers.ListAll(ctx, listReq)
if err != nil {
return err
@ -432,8 +422,10 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{}
var updateReq sharing.UpdateProvider
var updateJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateReq.Comment, "comment", updateReq.Comment, `Description about the provider.`)
cmd.Flags().StringVar(&updateReq.Name, "name", updateReq.Name, `The name of the Provider.`)
@ -456,6 +448,12 @@ func newUpdate() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = updateJson.Unmarshal(&updateReq)
if err != nil {
return err
}
}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down."

View File

@ -72,14 +72,6 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
@ -281,10 +273,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq sql.ListQueriesRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.Order, "order", listReq.Order, `Name of query attribute to order by.`)
cmd.Flags().IntVar(&listReq.Page, "page", listReq.Page, `Page number to retrieve.`)
@ -302,9 +292,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -313,14 +300,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.Queries.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -5,7 +5,6 @@ package query_history
import (
"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"
)
@ -46,10 +45,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq sql.ListQueryHistoryRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
// TODO: complex arg: filter_by
cmd.Flags().BoolVar(&listReq.IncludeMetrics, "include-metrics", listReq.IncludeMetrics, `Whether to include metrics about query.`)
@ -68,9 +65,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -79,14 +73,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.QueryHistory.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -180,20 +180,12 @@ func newUpdate() *cobra.Command {
// TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Use = "update ID"
cmd.Use = "update"
cmd.Short = `Edit existing visualization.`
cmd.Long = `Edit existing visualization.`
cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()

View File

@ -104,8 +104,11 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[1], &createReq.AuthenticationType)
if err != nil {
return fmt.Errorf("invalid AUTHENTICATION_TYPE: %s", args[1])
@ -299,10 +302,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq sharing.ListRecipientsRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.DataRecipientGlobalMetastoreId, "data-recipient-global-metastore-id", listReq.DataRecipientGlobalMetastoreId, `If not provided, all recipients will be returned.`)
@ -319,9 +320,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -330,14 +328,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.Recipients.ListAll(ctx, listReq)
if err != nil {
return err
@ -376,10 +366,12 @@ func newRotateToken() *cobra.Command {
cmd := &cobra.Command{}
var rotateTokenReq sharing.RotateRecipientToken
var rotateTokenJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&rotateTokenJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Use = "rotate-token EXISTING_TOKEN_EXPIRE_IN_SECONDS NAME"
cmd.Use = "rotate-token NAME EXISTING_TOKEN_EXPIRE_IN_SECONDS"
cmd.Short = `Rotate a token.`
cmd.Long = `Rotate a token.
@ -390,6 +382,9 @@ func newRotateToken() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(1)
}
return check(cmd, args)
}
@ -398,11 +393,19 @@ func newRotateToken() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
_, err = fmt.Sscan(args[0], &rotateTokenReq.ExistingTokenExpireInSeconds)
if err != nil {
return fmt.Errorf("invalid EXISTING_TOKEN_EXPIRE_IN_SECONDS: %s", args[0])
if cmd.Flags().Changed("json") {
err = rotateTokenJson.Unmarshal(&rotateTokenReq)
if err != nil {
return err
}
}
rotateTokenReq.Name = args[0]
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[1], &rotateTokenReq.ExistingTokenExpireInSeconds)
if err != nil {
return fmt.Errorf("invalid EXISTING_TOKEN_EXPIRE_IN_SECONDS: %s", args[1])
}
}
rotateTokenReq.Name = args[1]
response, err := w.Recipients.RotateToken(ctx, rotateTokenReq)
if err != nil {

View File

@ -121,9 +121,14 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.CatalogName = args[0]
}
if !cmd.Flags().Changed("json") {
createReq.SchemaName = args[1]
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[2]
}
@ -389,10 +394,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq catalog.ListRegisteredModelsRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.CatalogName, "catalog-name", listReq.CatalogName, `The identifier of the catalog under which to list registered models.`)
cmd.Flags().IntVar(&listReq.MaxResults, "max-results", listReq.MaxResults, `Max number of registered models to return.`)
@ -420,9 +423,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -431,14 +431,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.RegisteredModels.ListAll(ctx, listReq)
if err != nil {
return err
@ -477,8 +469,10 @@ func newSetAlias() *cobra.Command {
cmd := &cobra.Command{}
var setAliasReq catalog.SetRegisteredModelAliasRequest
var setAliasJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&setAliasJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Use = "set-alias FULL_NAME ALIAS VERSION_NUM"
cmd.Short = `Set a Registered Model Alias.`
@ -495,6 +489,9 @@ func newSetAlias() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(2)
}
return check(cmd, args)
}
@ -503,11 +500,19 @@ func newSetAlias() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = setAliasJson.Unmarshal(&setAliasReq)
if err != nil {
return err
}
}
setAliasReq.FullName = args[0]
setAliasReq.Alias = args[1]
_, err = fmt.Sscan(args[2], &setAliasReq.VersionNum)
if err != nil {
return fmt.Errorf("invalid VERSION_NUM: %s", args[2])
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[2], &setAliasReq.VersionNum)
if err != nil {
return fmt.Errorf("invalid VERSION_NUM: %s", args[2])
}
}
response, err := w.RegisteredModels.SetAlias(ctx, setAliasReq)
@ -548,8 +553,10 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{}
var updateReq catalog.UpdateRegisteredModelRequest
var updateJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateReq.Comment, "comment", updateReq.Comment, `The comment attached to the registered model.`)
cmd.Flags().StringVar(&updateReq.Name, "name", updateReq.Name, `The name of the registered model.`)
@ -576,6 +583,12 @@ func newUpdate() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = updateJson.Unmarshal(&updateReq)
if err != nil {
return err
}
}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No FULL_NAME argument specified. Loading names for Registered Models drop-down."

View File

@ -93,8 +93,11 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Url = args[0]
}
if !cmd.Flags().Changed("json") {
createReq.Provider = args[1]
}
@ -435,10 +438,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq workspace.ListReposRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.NextPageToken, "next-page-token", listReq.NextPageToken, `Token used to get the next page of results.`)
cmd.Flags().StringVar(&listReq.PathPrefix, "path-prefix", listReq.PathPrefix, `Filters repos that have paths starting with the given path prefix.`)
@ -454,9 +455,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -465,14 +463,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.Repos.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -89,8 +89,11 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
createReq.CatalogName = args[1]
}

View File

@ -96,7 +96,8 @@ func newCreateScope() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createScopeReq.Scope = args[0]
}
@ -174,8 +175,11 @@ func newDeleteAcl() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
deleteAclReq.Scope = args[0]
}
if !cmd.Flags().Changed("json") {
deleteAclReq.Principal = args[1]
}
@ -252,7 +256,8 @@ func newDeleteScope() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
deleteScopeReq.Scope = args[0]
}
@ -330,8 +335,11 @@ func newDeleteSecret() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
deleteSecretReq.Scope = args[0]
}
if !cmd.Flags().Changed("json") {
deleteSecretReq.Key = args[1]
}
@ -754,9 +762,14 @@ func newPutAcl() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
putAclReq.Scope = args[0]
}
if !cmd.Flags().Changed("json") {
putAclReq.Principal = args[1]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[2], &putAclReq.Permission)
if err != nil {
return fmt.Errorf("invalid PERMISSION: %s", args[2])

View File

@ -77,9 +77,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -93,7 +90,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.ServicePrincipals.Create(ctx, createReq)
@ -281,10 +277,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq iam.ListServicePrincipalsRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.Attributes, "attributes", listReq.Attributes, `Comma-separated list of attributes to return in response.`)
cmd.Flags().IntVar(&listReq.Count, "count", listReq.Count, `Desired number of results per page.`)
@ -304,9 +298,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -315,14 +306,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.ServicePrincipals.ListAll(ctx, listReq)
if err != nil {
return err

View File

@ -194,9 +194,6 @@ func newUpdateDefaultWorkspaceNamespace() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -210,7 +207,6 @@ func newUpdateDefaultWorkspaceNamespace() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.Settings.UpdateDefaultWorkspaceNamespace(ctx, updateDefaultWorkspaceNamespaceReq)

View File

@ -85,7 +85,8 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}

View File

@ -99,7 +99,8 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}
@ -471,9 +472,6 @@ func newValidate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -487,7 +485,6 @@ func newValidate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.StorageCredentials.Validate(ctx, validateReq)

View File

@ -7,6 +7,7 @@ import (
"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/catalog"
"github.com/spf13/cobra"
)
@ -370,8 +371,10 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{}
var updateReq catalog.UpdateTableRequest
var updateJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateReq.Owner, "owner", updateReq.Owner, ``)
@ -395,6 +398,12 @@ func newUpdate() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = updateJson.Unmarshal(&updateReq)
if err != nil {
return err
}
}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No FULL_NAME argument specified. Loading names for Tables drop-down."

View File

@ -83,8 +83,11 @@ func newCreateOboToken() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createOboTokenReq.ApplicationId = args[0]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[1], &createOboTokenReq.LifetimeSeconds)
if err != nil {
return fmt.Errorf("invalid LIFETIME_SECONDS: %s", args[1])
@ -372,10 +375,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq settings.ListTokenManagementRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.CreatedById, "created-by-id", listReq.CreatedById, `User ID of the user that created the token.`)
cmd.Flags().StringVar(&listReq.CreatedByUsername, "created-by-username", listReq.CreatedByUsername, `Username of the user that created the token.`)
@ -390,9 +391,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -401,14 +399,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.TokenManagement.ListAll(ctx, listReq)
if err != nil {
return err
@ -465,9 +455,6 @@ func newSetPermissions() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -481,7 +468,6 @@ func newSetPermissions() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.TokenManagement.SetPermissions(ctx, setPermissionsReq)
@ -540,9 +526,6 @@ func newUpdatePermissions() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -556,7 +539,6 @@ func newUpdatePermissions() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.TokenManagement.UpdatePermissions(ctx, updatePermissionsReq)

View File

@ -70,9 +70,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -86,7 +83,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.Tokens.Create(ctx, createReq)

View File

@ -85,9 +85,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -101,7 +98,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.Users.Create(ctx, createReq)
@ -386,10 +382,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq iam.ListUsersRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&listReq.Attributes, "attributes", listReq.Attributes, `Comma-separated list of attributes to return in response.`)
cmd.Flags().IntVar(&listReq.Count, "count", listReq.Count, `Desired number of results per page.`)
@ -409,9 +403,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -420,14 +411,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.Users.ListAll(ctx, listReq)
if err != nil {
return err
@ -569,9 +552,6 @@ func newSetPermissions() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -585,7 +565,6 @@ func newSetPermissions() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.Users.SetPermissions(ctx, setPermissionsReq)
@ -736,9 +715,6 @@ func newUpdatePermissions() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -752,7 +728,6 @@ func newUpdatePermissions() *cobra.Command {
if err != nil {
return err
}
} else {
}
response, err := w.Users.UpdatePermissions(ctx, updatePermissionsReq)

View File

@ -106,10 +106,17 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
createReq.CatalogName = args[0]
}
if !cmd.Flags().Changed("json") {
createReq.SchemaName = args[1]
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[2]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[3], &createReq.VolumeType)
if err != nil {
return fmt.Errorf("invalid VOLUME_TYPE: %s", args[3])
@ -384,8 +391,10 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{}
var updateReq catalog.UpdateVolumeRequestContent
var updateJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateReq.Comment, "comment", updateReq.Comment, `The comment attached to the volume.`)
cmd.Flags().StringVar(&updateReq.Name, "name", updateReq.Name, `The name of the volume.`)
@ -411,6 +420,12 @@ func newUpdate() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = updateJson.Unmarshal(&updateReq)
if err != nil {
return err
}
}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No FULL_NAME_ARG argument specified. Loading names for Volumes drop-down."

View File

@ -85,9 +85,6 @@ func newCreate() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -101,7 +98,6 @@ func newCreate() *cobra.Command {
if err != nil {
return err
}
} else {
}
wait, err := w.Warehouses.Create(ctx, createReq)
@ -627,10 +623,8 @@ func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq sql.ListWarehousesRequest
var listJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().IntVar(&listReq.RunAsUserId, "run-as-user-id", listReq.RunAsUserId, `Service Principal which will be used to fetch the list of warehouses.`)
@ -644,9 +638,6 @@ func newList() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -655,14 +646,6 @@ func newList() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = listJson.Unmarshal(&listReq)
if err != nil {
return err
}
} else {
}
response, err := w.Warehouses.ListAll(ctx, listReq)
if err != nil {
return err
@ -811,9 +794,6 @@ func newSetWorkspaceWarehouseConfig() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -827,7 +807,6 @@ func newSetWorkspaceWarehouseConfig() *cobra.Command {
if err != nil {
return err
}
} else {
}
err = w.Warehouses.SetWorkspaceWarehouseConfig(ctx, setWorkspaceWarehouseConfigReq)

View File

@ -5,7 +5,6 @@ package workspace_conf
import (
"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/settings"
"github.com/spf13/cobra"
)
@ -107,10 +106,8 @@ func newSetStatus() *cobra.Command {
cmd := &cobra.Command{}
var setStatusReq settings.WorkspaceConf
var setStatusJson flags.JsonFlag
// TODO: short flags
cmd.Flags().Var(&setStatusJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Use = "set-status"
cmd.Short = `Enable/disable features.`
@ -123,9 +120,6 @@ func newSetStatus() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(0)
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
return check(cmd, args)
}
@ -134,14 +128,6 @@ func newSetStatus() *cobra.Command {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
err = setStatusJson.Unmarshal(&setStatusReq)
if err != nil {
return err
}
} else {
}
err = w.WorkspaceConf.SetStatus(ctx, setStatusReq)
if err != nil {
return err

View File

@ -453,7 +453,8 @@ func newImport() *cobra.Command {
if err != nil {
return err
}
} else {
}
if !cmd.Flags().Changed("json") {
importReq.Path = args[0]
}