Skip to content

Commit

Permalink
Improve error message when --json flag is specified (#933)
Browse files Browse the repository at this point in the history
## 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
```
  • Loading branch information
andrewnester authored Nov 8, 2023
1 parent e68a88e commit 47e434d
Show file tree
Hide file tree
Showing 28 changed files with 438 additions and 142 deletions.
12 changes: 10 additions & 2 deletions .codegen/service.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
8 changes: 6 additions & 2 deletions cmd/account/log-delivery/log-delivery.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions cmd/account/networks/networks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions cmd/account/private-access/private-access.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions cmd/account/vpc-endpoints/vpc-endpoints.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions cmd/account/workspaces/workspaces.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions cmd/workspace/catalogs/catalogs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions cmd/workspace/cluster-policies/cluster-policies.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions cmd/workspace/clusters/clusters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 47e434d

Please sign in to comment.