Improve error message when `--json` flag is specified (#933)

## Changes
Improve error message when --json input is provided

## Tests
```
cli % databricks model-registry create-model mymodel --json @./input.json              
Error: when --json flag is specified, no positional arguments are required. Provide NAME in your JSON input
```
This commit is contained in:
Andrew Nester 2023-11-08 16:07:29 +01:00 committed by GitHub
parent e68a88e14d
commit 47e434db2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 438 additions and 142 deletions

View File

@ -141,12 +141,20 @@ func new{{.PascalName}}() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
{{if $hasRequiredArgs }} {{if $hasRequiredArgs }}
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs({{len .Request.RequiredFields}})
{{- if and .CanUseJson .Request.HasRequiredRequestBodyFields }} {{- if and .CanUseJson .Request.HasRequiredRequestBodyFields }}
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs({{len .Request.RequiredPathFields}}) err := cobra.ExactArgs({{len .Request.RequiredPathFields}})(cmd, args)
if err != nil {
{{- if eq 0 (len .Request.RequiredPathFields) }}
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide{{- range $index, $field := .Request.RequiredFields}}{{if $index}},{{end}} '{{$field.Name}}'{{end}} in your JSON input")
{{- else }}
return fmt.Errorf("when --json flag is specified, provide only{{- range $index, $field := .Request.RequiredPathFields}}{{if $index}},{{end}} {{$field.ConstantName}}{{end}} as positional arguments. Provide{{- range $index, $field := .Request.RequiredRequestBodyFields}}{{if $index}},{{end}} '{{$field.Name}}'{{end}} in your JSON input")
{{- end }}
}
return nil
} }
{{- end }} {{- end }}
check := cobra.ExactArgs({{len .Request.RequiredFields}})
return check(cmd, args) return check(cmd, args)
} }
{{end}} {{end}}

View File

@ -356,10 +356,14 @@ func newPatchStatus() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(1) err := cobra.ExactArgs(1)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, provide only LOG_DELIVERY_CONFIGURATION_ID as positional arguments. Provide 'status' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -71,10 +71,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'network_name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -80,10 +80,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'private_access_settings_name', 'region' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -390,10 +394,14 @@ func newReplace() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(1) err := cobra.ExactArgs(1)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, provide only PRIVATE_ACCESS_SETTINGS_ID as positional arguments. Provide 'private_access_settings_name', 'region' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -78,10 +78,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'vpc_endpoint_name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -99,10 +99,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'workspace_name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -3,6 +3,8 @@
package catalogs package catalogs
import ( import (
"fmt"
"github.com/databricks/cli/cmd/root" "github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/flags"
@ -76,10 +78,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -91,10 +91,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -255,10 +259,14 @@ func newEdit() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'policy_id', 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -90,10 +90,14 @@ func newChangeOwner() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'cluster_id', 'owner_username' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -207,10 +211,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'spark_version' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -439,10 +447,14 @@ func newEdit() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'cluster_id', 'spark_version' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -78,10 +78,14 @@ func newCreateExperiment() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -230,10 +234,14 @@ func newDeleteExperiment() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'experiment_id' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -304,10 +312,14 @@ func newDeleteRun() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'run_id' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -381,10 +393,14 @@ func newDeleteRuns() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'experiment_id', 'max_timestamp_millis' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -462,10 +478,14 @@ func newDeleteTag() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'run_id', 'key' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -1241,10 +1261,14 @@ func newLogMetric() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'key', 'value', 'timestamp' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }
@ -1405,10 +1429,14 @@ func newLogParam() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'key', 'value' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -1487,10 +1515,14 @@ func newRestoreExperiment() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'experiment_id' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -1561,10 +1593,14 @@ func newRestoreRun() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'run_id' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -1638,10 +1674,14 @@ func newRestoreRuns() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'experiment_id', 'min_timestamp_millis' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -1869,10 +1909,14 @@ func newSetExperimentTag() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'experiment_id', 'key', 'value' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }
@ -2025,10 +2069,14 @@ func newSetTag() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'key', 'value' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -2104,10 +2152,14 @@ func newUpdateExperiment() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'experiment_id' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -3,6 +3,8 @@
package external_locations package external_locations
import ( import (
"fmt"
"github.com/databricks/cli/cmd/root" "github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/flags"
@ -80,10 +82,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'url', 'credential_name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -73,10 +73,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'git_provider' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -73,10 +73,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'script' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -351,10 +355,14 @@ func newUpdate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(1) err := cobra.ExactArgs(1)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, provide only SCRIPT_ID as positional arguments. Provide 'name', 'script' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -91,10 +91,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'instance_pool_name', 'node_type_id' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -256,10 +260,14 @@ func newEdit() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'instance_pool_id', 'instance_pool_name', 'node_type_id' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -3,6 +3,8 @@
package instance_profiles package instance_profiles
import ( import (
"fmt"
"github.com/databricks/cli/cmd/root" "github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/flags"
@ -70,10 +72,14 @@ func newAdd() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'instance_profile_arn' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -161,10 +167,14 @@ func newEdit() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'instance_profile_arn' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -288,10 +298,14 @@ func newRemove() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'instance_profile_arn' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -76,10 +76,14 @@ func newAssign() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(1) err := cobra.ExactArgs(1)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, provide only WORKSPACE_ID as positional arguments. Provide 'metastore_id', 'default_catalog_name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }
@ -159,10 +163,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'storage_root' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -362,10 +370,14 @@ func newEnableOptimization() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'metastore_id', 'enable' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -71,10 +71,14 @@ func newApproveTransitionRequest() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(4)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'version', 'stage', 'archive_existing_versions' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(4)
return check(cmd, args) return check(cmd, args)
} }
@ -162,10 +166,14 @@ func newCreateComment() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'version', 'comment' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }
@ -248,10 +256,14 @@ func newCreateModel() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -327,10 +339,14 @@ func newCreateModelVersion() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'source' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -406,10 +422,14 @@ func newCreateTransitionRequest() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'version', 'stage' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }
@ -1005,10 +1025,14 @@ func newGetLatestVersions() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -1583,10 +1607,14 @@ func newRejectTransitionRequest() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'version', 'stage' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }
@ -1668,10 +1696,14 @@ func newRenameModel() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -1870,10 +1902,14 @@ func newSetModelTag() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'key', 'value' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }
@ -1950,10 +1986,14 @@ func newSetModelVersionTag() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(4)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'version', 'key', 'value' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(4)
return check(cmd, args) return check(cmd, args)
} }
@ -2109,10 +2149,14 @@ func newTestRegistryWebhook() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'id' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -2189,10 +2233,14 @@ func newTransitionStage() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(4)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'version', 'stage', 'archive_existing_versions' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(4)
return check(cmd, args) return check(cmd, args)
} }
@ -2278,10 +2326,14 @@ func newUpdateComment() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'id', 'comment' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -2357,10 +2409,14 @@ func newUpdateModel() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -2433,10 +2489,14 @@ func newUpdateModelVersion() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'version' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -2590,10 +2650,14 @@ func newUpdateWebhook() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'id' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -68,10 +68,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'authentication_type' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -87,10 +87,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'authentication_type' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -381,10 +385,14 @@ func newRotateToken() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(1) err := cobra.ExactArgs(1)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, provide only NAME as positional arguments. Provide 'existing_token_expire_in_seconds' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -104,10 +104,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'catalog_name', 'schema_name', 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }
@ -488,10 +492,14 @@ func newSetAlias() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(2) err := cobra.ExactArgs(2)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, provide only FULL_NAME, ALIAS as positional arguments. Provide 'version_num' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -76,10 +76,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'url', 'provider' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -72,10 +72,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name', 'catalog_name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -79,10 +79,14 @@ func newCreateScope() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'scope' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -158,10 +162,14 @@ func newDeleteAcl() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'scope', 'principal' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -239,10 +247,14 @@ func newDeleteScope() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'scope' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -318,10 +330,14 @@ func newDeleteSecret() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'scope', 'key' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -745,10 +761,14 @@ func newPutAcl() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(3)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'scope', 'principal', 'permission' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(3)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -3,6 +3,8 @@
package shares package shares
import ( import (
"fmt"
"github.com/databricks/cli/cmd/root" "github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/flags"
@ -68,10 +70,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -82,10 +82,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -66,10 +66,14 @@ func newCreateOboToken() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'application_id', 'lifetime_seconds' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -89,10 +89,14 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(4)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'catalog_name', 'schema_name', 'name', 'volume_type' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(4)
return check(cmd, args) return check(cmd, args)
} }

View File

@ -436,10 +436,14 @@ func newImport() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0) err := cobra.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'path' in your JSON input")
}
return nil
} }
check := cobra.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }