diff --git a/.codegen/service.go.tmpl b/.codegen/service.go.tmpl index 27b9a754..5feb0c87 100644 --- a/.codegen/service.go.tmpl +++ b/.codegen/service.go.tmpl @@ -141,12 +141,20 @@ func new{{.PascalName}}() *cobra.Command { cmd.Annotations = make(map[string]string) {{if $hasRequiredArgs }} cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs({{len .Request.RequiredFields}}) {{- if and .CanUseJson .Request.HasRequiredRequestBodyFields }} 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 }} + check := cobra.ExactArgs({{len .Request.RequiredFields}}) return check(cmd, args) } {{end}} diff --git a/cmd/account/log-delivery/log-delivery.go b/cmd/account/log-delivery/log-delivery.go index 48ebe9e9..fdc5e386 100755 --- a/cmd/account/log-delivery/log-delivery.go +++ b/cmd/account/log-delivery/log-delivery.go @@ -356,10 +356,14 @@ func newPatchStatus() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } diff --git a/cmd/account/networks/networks.go b/cmd/account/networks/networks.go index 74b3ffde..1aa2520f 100755 --- a/cmd/account/networks/networks.go +++ b/cmd/account/networks/networks.go @@ -71,10 +71,14 @@ func newCreate() *cobra.Command { 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) + 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) } diff --git a/cmd/account/private-access/private-access.go b/cmd/account/private-access/private-access.go index 094c030b..4aff4192 100755 --- a/cmd/account/private-access/private-access.go +++ b/cmd/account/private-access/private-access.go @@ -80,10 +80,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -390,10 +394,14 @@ func newReplace() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } diff --git a/cmd/account/vpc-endpoints/vpc-endpoints.go b/cmd/account/vpc-endpoints/vpc-endpoints.go index 4cefe242..8c46ab82 100755 --- a/cmd/account/vpc-endpoints/vpc-endpoints.go +++ b/cmd/account/vpc-endpoints/vpc-endpoints.go @@ -78,10 +78,14 @@ func newCreate() *cobra.Command { 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) + 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) } diff --git a/cmd/account/workspaces/workspaces.go b/cmd/account/workspaces/workspaces.go index 993e569f..1a6aa90d 100755 --- a/cmd/account/workspaces/workspaces.go +++ b/cmd/account/workspaces/workspaces.go @@ -99,10 +99,14 @@ func newCreate() *cobra.Command { 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) + 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) } diff --git a/cmd/workspace/catalogs/catalogs.go b/cmd/workspace/catalogs/catalogs.go index d1b54452..7846c0e0 100755 --- a/cmd/workspace/catalogs/catalogs.go +++ b/cmd/workspace/catalogs/catalogs.go @@ -3,6 +3,8 @@ package catalogs import ( + "fmt" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/flags" @@ -76,10 +78,14 @@ func newCreate() *cobra.Command { 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) + 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) } diff --git a/cmd/workspace/cluster-policies/cluster-policies.go b/cmd/workspace/cluster-policies/cluster-policies.go index 0bd7b4a9..1412b460 100755 --- a/cmd/workspace/cluster-policies/cluster-policies.go +++ b/cmd/workspace/cluster-policies/cluster-policies.go @@ -91,10 +91,14 @@ func newCreate() *cobra.Command { 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) + 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) } @@ -255,10 +259,14 @@ func newEdit() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } diff --git a/cmd/workspace/clusters/clusters.go b/cmd/workspace/clusters/clusters.go index e4fb6e0a..bc45d14a 100755 --- a/cmd/workspace/clusters/clusters.go +++ b/cmd/workspace/clusters/clusters.go @@ -90,10 +90,14 @@ func newChangeOwner() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -207,10 +211,14 @@ func newCreate() *cobra.Command { 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) + 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) } @@ -439,10 +447,14 @@ func newEdit() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } diff --git a/cmd/workspace/experiments/experiments.go b/cmd/workspace/experiments/experiments.go index ed807ae5..420593a2 100755 --- a/cmd/workspace/experiments/experiments.go +++ b/cmd/workspace/experiments/experiments.go @@ -78,10 +78,14 @@ func newCreateExperiment() *cobra.Command { 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) + 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) } @@ -230,10 +234,14 @@ func newDeleteExperiment() *cobra.Command { 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) + 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) } @@ -304,10 +312,14 @@ func newDeleteRun() *cobra.Command { 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) + 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) } @@ -381,10 +393,14 @@ func newDeleteRuns() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -462,10 +478,14 @@ func newDeleteTag() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -1241,10 +1261,14 @@ func newLogMetric() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } @@ -1405,10 +1429,14 @@ func newLogParam() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -1487,10 +1515,14 @@ func newRestoreExperiment() *cobra.Command { 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) + 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) } @@ -1561,10 +1593,14 @@ func newRestoreRun() *cobra.Command { 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) + 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) } @@ -1638,10 +1674,14 @@ func newRestoreRuns() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -1869,10 +1909,14 @@ func newSetExperimentTag() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } @@ -2025,10 +2069,14 @@ func newSetTag() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -2104,10 +2152,14 @@ func newUpdateExperiment() *cobra.Command { 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) + 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) } diff --git a/cmd/workspace/external-locations/external-locations.go b/cmd/workspace/external-locations/external-locations.go index d510d2a9..a5c69259 100755 --- a/cmd/workspace/external-locations/external-locations.go +++ b/cmd/workspace/external-locations/external-locations.go @@ -3,6 +3,8 @@ package external_locations import ( + "fmt" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/flags" @@ -80,10 +82,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } diff --git a/cmd/workspace/git-credentials/git-credentials.go b/cmd/workspace/git-credentials/git-credentials.go index 81348155..1d9e64a0 100755 --- a/cmd/workspace/git-credentials/git-credentials.go +++ b/cmd/workspace/git-credentials/git-credentials.go @@ -73,10 +73,14 @@ func newCreate() *cobra.Command { 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) + 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) } diff --git a/cmd/workspace/global-init-scripts/global-init-scripts.go b/cmd/workspace/global-init-scripts/global-init-scripts.go index 513b9637..3674d405 100755 --- a/cmd/workspace/global-init-scripts/global-init-scripts.go +++ b/cmd/workspace/global-init-scripts/global-init-scripts.go @@ -73,10 +73,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -351,10 +355,14 @@ func newUpdate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } diff --git a/cmd/workspace/instance-pools/instance-pools.go b/cmd/workspace/instance-pools/instance-pools.go index 1109b921..ae23eac0 100755 --- a/cmd/workspace/instance-pools/instance-pools.go +++ b/cmd/workspace/instance-pools/instance-pools.go @@ -91,10 +91,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -256,10 +260,14 @@ func newEdit() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } diff --git a/cmd/workspace/instance-profiles/instance-profiles.go b/cmd/workspace/instance-profiles/instance-profiles.go index b3fdfc65..085707b7 100755 --- a/cmd/workspace/instance-profiles/instance-profiles.go +++ b/cmd/workspace/instance-profiles/instance-profiles.go @@ -3,6 +3,8 @@ package instance_profiles import ( + "fmt" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/flags" @@ -70,10 +72,14 @@ func newAdd() *cobra.Command { 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) + 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) } @@ -161,10 +167,14 @@ func newEdit() *cobra.Command { 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) + 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) } @@ -288,10 +298,14 @@ func newRemove() *cobra.Command { 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) + 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) } diff --git a/cmd/workspace/metastores/metastores.go b/cmd/workspace/metastores/metastores.go index 92144ec7..d74c9bbc 100755 --- a/cmd/workspace/metastores/metastores.go +++ b/cmd/workspace/metastores/metastores.go @@ -76,10 +76,14 @@ func newAssign() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } @@ -159,10 +163,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -362,10 +370,14 @@ func newEnableOptimization() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } diff --git a/cmd/workspace/model-registry/model-registry.go b/cmd/workspace/model-registry/model-registry.go index c0fe43c7..1ae5c8eb 100755 --- a/cmd/workspace/model-registry/model-registry.go +++ b/cmd/workspace/model-registry/model-registry.go @@ -71,10 +71,14 @@ func newApproveTransitionRequest() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(4) 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) } @@ -162,10 +166,14 @@ func newCreateComment() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } @@ -248,10 +256,14 @@ func newCreateModel() *cobra.Command { 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) + 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) } @@ -327,10 +339,14 @@ func newCreateModelVersion() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -406,10 +422,14 @@ func newCreateTransitionRequest() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } @@ -1005,10 +1025,14 @@ func newGetLatestVersions() *cobra.Command { 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) + 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) } @@ -1583,10 +1607,14 @@ func newRejectTransitionRequest() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } @@ -1668,10 +1696,14 @@ func newRenameModel() *cobra.Command { 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) + 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) } @@ -1870,10 +1902,14 @@ func newSetModelTag() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } @@ -1950,10 +1986,14 @@ func newSetModelVersionTag() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(4) 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) } @@ -2109,10 +2149,14 @@ func newTestRegistryWebhook() *cobra.Command { 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) + 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) } @@ -2189,10 +2233,14 @@ func newTransitionStage() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(4) 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) } @@ -2278,10 +2326,14 @@ func newUpdateComment() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -2357,10 +2409,14 @@ func newUpdateModel() *cobra.Command { 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) + 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) } @@ -2433,10 +2489,14 @@ func newUpdateModelVersion() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -2590,10 +2650,14 @@ func newUpdateWebhook() *cobra.Command { 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) + 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) } diff --git a/cmd/workspace/providers/providers.go b/cmd/workspace/providers/providers.go index 69a16725..1da8202d 100755 --- a/cmd/workspace/providers/providers.go +++ b/cmd/workspace/providers/providers.go @@ -68,10 +68,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } diff --git a/cmd/workspace/recipients/recipients.go b/cmd/workspace/recipients/recipients.go index 53576043..260729cb 100755 --- a/cmd/workspace/recipients/recipients.go +++ b/cmd/workspace/recipients/recipients.go @@ -87,10 +87,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -381,10 +385,14 @@ func newRotateToken() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } diff --git a/cmd/workspace/registered-models/registered-models.go b/cmd/workspace/registered-models/registered-models.go index 64f40e17..e594f2eb 100755 --- a/cmd/workspace/registered-models/registered-models.go +++ b/cmd/workspace/registered-models/registered-models.go @@ -104,10 +104,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } @@ -488,10 +492,14 @@ func newSetAlias() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } diff --git a/cmd/workspace/repos/repos.go b/cmd/workspace/repos/repos.go index 1a2a43b4..e8261c01 100755 --- a/cmd/workspace/repos/repos.go +++ b/cmd/workspace/repos/repos.go @@ -76,10 +76,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } diff --git a/cmd/workspace/schemas/schemas.go b/cmd/workspace/schemas/schemas.go index 70d8b633..8b42281a 100755 --- a/cmd/workspace/schemas/schemas.go +++ b/cmd/workspace/schemas/schemas.go @@ -72,10 +72,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } diff --git a/cmd/workspace/secrets/secrets.go b/cmd/workspace/secrets/secrets.go index 9715d390..c124e7ef 100755 --- a/cmd/workspace/secrets/secrets.go +++ b/cmd/workspace/secrets/secrets.go @@ -79,10 +79,14 @@ func newCreateScope() *cobra.Command { 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) + 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) } @@ -158,10 +162,14 @@ func newDeleteAcl() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -239,10 +247,14 @@ func newDeleteScope() *cobra.Command { 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) + 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) } @@ -318,10 +330,14 @@ func newDeleteSecret() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } @@ -745,10 +761,14 @@ func newPutAcl() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(3) 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) } diff --git a/cmd/workspace/shares/shares.go b/cmd/workspace/shares/shares.go index c8cab3b7..de6cc5df 100755 --- a/cmd/workspace/shares/shares.go +++ b/cmd/workspace/shares/shares.go @@ -3,6 +3,8 @@ package shares import ( + "fmt" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/flags" @@ -68,10 +70,14 @@ func newCreate() *cobra.Command { 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) + 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) } diff --git a/cmd/workspace/storage-credentials/storage-credentials.go b/cmd/workspace/storage-credentials/storage-credentials.go index 00c0c215..b70d949a 100755 --- a/cmd/workspace/storage-credentials/storage-credentials.go +++ b/cmd/workspace/storage-credentials/storage-credentials.go @@ -82,10 +82,14 @@ func newCreate() *cobra.Command { 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) + 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) } diff --git a/cmd/workspace/token-management/token-management.go b/cmd/workspace/token-management/token-management.go index 5d34a2c7..b74b0483 100755 --- a/cmd/workspace/token-management/token-management.go +++ b/cmd/workspace/token-management/token-management.go @@ -66,10 +66,14 @@ func newCreateOboToken() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) 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) } diff --git a/cmd/workspace/volumes/volumes.go b/cmd/workspace/volumes/volumes.go index d443cea9..ef90eec5 100755 --- a/cmd/workspace/volumes/volumes.go +++ b/cmd/workspace/volumes/volumes.go @@ -89,10 +89,14 @@ func newCreate() *cobra.Command { cmd.Annotations = make(map[string]string) cmd.Args = func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(4) 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) } diff --git a/cmd/workspace/workspace/workspace.go b/cmd/workspace/workspace/workspace.go index 4af888ac..dcfb7147 100755 --- a/cmd/workspace/workspace/workspace.go +++ b/cmd/workspace/workspace/workspace.go @@ -436,10 +436,14 @@ func newImport() *cobra.Command { 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) + 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) }