mirror of https://github.com/databricks/cli.git
Fixed requiring positional arguments for API URL parameters (#878)
## Changes Some commands such as update commands have an argument in their url, for example in pipeline we have `PUT pipelines/<id>` to update the pipeline. Such parameters must be required and respected even if `--json` flag with the payload passed. Note: this depends on these PRs in Go SDK: https://github.com/databricks/databricks-sdk-go/pull/660 https://github.com/databricks/databricks-sdk-go/pull/661 ## Tests Manually running `databricks pipelines update`
This commit is contained in:
parent
3700785dfa
commit
4ad68eb314
|
@ -78,8 +78,7 @@ var {{.CamelName}}Overrides []func(
|
|||
func new{{.PascalName}}() *cobra.Command {
|
||||
cmd := &cobra.Command{}
|
||||
|
||||
{{- $useJsonForAllFields := or .IsJsonOnly (and .Request (or (not .Request.IsAllRequiredFieldsPrimitive) .Request.HasRequiredNonBodyField)) -}}
|
||||
{{- $needJsonFlag := or $useJsonForAllFields (and .Request (not .Request.IsOnlyPrimitiveFields)) -}}
|
||||
{{- $needJsonFlag := or .CanSetRequiredFieldsFromJson (and .Request (not .Request.IsOnlyPrimitiveFields)) -}}
|
||||
|
||||
{{- if .Request}}
|
||||
|
||||
|
@ -143,7 +142,7 @@ func new{{.PascalName}}() *cobra.Command {
|
|||
{{if $hasRequiredArgs }}
|
||||
cmd.Args = func(cmd *cobra.Command, args []string) error {
|
||||
check := cobra.ExactArgs({{len .Request.RequiredFields}})
|
||||
{{- if $useJsonForAllFields }}
|
||||
{{- if .CanSetRequiredFieldsFromJson }}
|
||||
if cmd.Flags().Changed("json") {
|
||||
check = cobra.ExactArgs(0)
|
||||
}
|
||||
|
@ -162,7 +161,7 @@ func new{{.PascalName}}() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}{{end}}{{if $useJsonForAllFields }} else {
|
||||
}{{end}}{{if .CanSetRequiredFieldsFromJson }} else {
|
||||
{{- end }}
|
||||
{{- if $hasIdPrompt}}
|
||||
if len(args) == 0 {
|
||||
|
@ -196,7 +195,7 @@ func new{{.PascalName}}() *cobra.Command {
|
|||
{{- else -}}
|
||||
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
|
||||
{{- end -}}
|
||||
{{if $useJsonForAllFields }}
|
||||
{{if .CanSetRequiredFieldsFromJson }}
|
||||
}
|
||||
{{end }}
|
||||
{{end}}
|
||||
|
|
|
@ -478,7 +478,7 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if len(args) == 0 {
|
||||
promptSpinner := cmdio.Spinner(ctx)
|
||||
promptSpinner <- "No ID argument specified. Loading names for Account Groups drop-down."
|
||||
|
@ -497,7 +497,6 @@ func newUpdate() *cobra.Command {
|
|||
return fmt.Errorf("expected to have databricks group id")
|
||||
}
|
||||
updateReq.Id = args[0]
|
||||
}
|
||||
|
||||
err = a.Groups.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -480,7 +480,7 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if len(args) == 0 {
|
||||
promptSpinner := cmdio.Spinner(ctx)
|
||||
promptSpinner <- "No ID argument specified. Loading names for Account Service Principals drop-down."
|
||||
|
@ -499,7 +499,6 @@ func newUpdate() *cobra.Command {
|
|||
return fmt.Errorf("expected to have databricks service principal id")
|
||||
}
|
||||
updateReq.Id = args[0]
|
||||
}
|
||||
|
||||
err = a.ServicePrincipals.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -488,7 +488,7 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if len(args) == 0 {
|
||||
promptSpinner := cmdio.Spinner(ctx)
|
||||
promptSpinner <- "No ID argument specified. Loading names for Account Users drop-down."
|
||||
|
@ -507,7 +507,6 @@ func newUpdate() *cobra.Command {
|
|||
return fmt.Errorf("expected to have databricks user id")
|
||||
}
|
||||
updateReq.Id = args[0]
|
||||
}
|
||||
|
||||
err = a.Users.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -337,9 +337,6 @@ func newUpdate() *cobra.Command {
|
|||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -353,9 +350,8 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
updateReq.Name = args[0]
|
||||
}
|
||||
updateReq.Name = args[0]
|
||||
|
||||
response, err := w.Catalogs.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -346,9 +346,6 @@ func newUpdate() *cobra.Command {
|
|||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -362,9 +359,8 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
updateReq.Name = args[0]
|
||||
}
|
||||
updateReq.Name = args[0]
|
||||
|
||||
response, err := w.ExternalLocations.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -478,7 +478,7 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if len(args) == 0 {
|
||||
promptSpinner := cmdio.Spinner(ctx)
|
||||
promptSpinner <- "No ID argument specified. Loading names for Groups drop-down."
|
||||
|
@ -497,7 +497,6 @@ func newUpdate() *cobra.Command {
|
|||
return fmt.Errorf("expected to have databricks group id")
|
||||
}
|
||||
updateReq.Id = args[0]
|
||||
}
|
||||
|
||||
err = w.Groups.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -1130,7 +1130,7 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if len(args) == 0 {
|
||||
promptSpinner := cmdio.Spinner(ctx)
|
||||
promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down."
|
||||
|
@ -1149,7 +1149,6 @@ func newUpdate() *cobra.Command {
|
|||
return fmt.Errorf("expected to have unique identifier for this pipeline")
|
||||
}
|
||||
updateReq.PipelineId = args[0]
|
||||
}
|
||||
|
||||
err = w.Pipelines.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -432,10 +432,8 @@ 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.`)
|
||||
|
@ -458,12 +456,6 @@ 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
|
||||
}
|
||||
} else {
|
||||
if len(args) == 0 {
|
||||
promptSpinner := cmdio.Spinner(ctx)
|
||||
promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down."
|
||||
|
@ -482,7 +474,6 @@ func newUpdate() *cobra.Command {
|
|||
return fmt.Errorf("expected to have the name of the provider")
|
||||
}
|
||||
updateReq.Name = args[0]
|
||||
}
|
||||
|
||||
response, err := w.Providers.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -547,7 +547,7 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if len(args) == 0 {
|
||||
promptSpinner := cmdio.Spinner(ctx)
|
||||
promptSpinner <- "No NAME argument specified. Loading names for Recipients drop-down."
|
||||
|
@ -566,7 +566,6 @@ func newUpdate() *cobra.Command {
|
|||
return fmt.Errorf("expected to have name of recipient")
|
||||
}
|
||||
updateReq.Name = args[0]
|
||||
}
|
||||
|
||||
err = w.Recipients.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -477,10 +477,8 @@ 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.`
|
||||
|
@ -497,9 +495,6 @@ 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(0)
|
||||
}
|
||||
return check(cmd, args)
|
||||
}
|
||||
|
||||
|
@ -508,19 +503,12 @@ 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
|
||||
}
|
||||
} else {
|
||||
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])
|
||||
}
|
||||
}
|
||||
|
||||
response, err := w.RegisteredModels.SetAlias(ctx, setAliasReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -480,7 +480,7 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if len(args) == 0 {
|
||||
promptSpinner := cmdio.Spinner(ctx)
|
||||
promptSpinner <- "No ID argument specified. Loading names for Service Principals drop-down."
|
||||
|
@ -499,7 +499,6 @@ func newUpdate() *cobra.Command {
|
|||
return fmt.Errorf("expected to have databricks service principal id")
|
||||
}
|
||||
updateReq.Id = args[0]
|
||||
}
|
||||
|
||||
err = w.ServicePrincipals.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -398,9 +398,6 @@ func newUpdate() *cobra.Command {
|
|||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -414,9 +411,8 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
updateReq.Name = args[0]
|
||||
}
|
||||
updateReq.Name = args[0]
|
||||
|
||||
response, err := w.Shares.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -378,7 +378,7 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if len(args) == 0 {
|
||||
promptSpinner := cmdio.Spinner(ctx)
|
||||
promptSpinner <- "No NAME argument specified. Loading names for Storage Credentials drop-down."
|
||||
|
@ -397,7 +397,6 @@ func newUpdate() *cobra.Command {
|
|||
return fmt.Errorf("expected to have the credential name")
|
||||
}
|
||||
updateReq.Name = args[0]
|
||||
}
|
||||
|
||||
response, err := w.StorageCredentials.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -660,7 +660,7 @@ func newUpdate() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if len(args) == 0 {
|
||||
promptSpinner := cmdio.Spinner(ctx)
|
||||
promptSpinner <- "No ID argument specified. Loading names for Users drop-down."
|
||||
|
@ -679,7 +679,6 @@ func newUpdate() *cobra.Command {
|
|||
return fmt.Errorf("expected to have databricks user id")
|
||||
}
|
||||
updateReq.Id = args[0]
|
||||
}
|
||||
|
||||
err = w.Users.Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue