Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed requiring positional arguments for API URL parameters #878

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .codegen/service.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ var {{.CamelName}}Overrides []func(
func new{{.PascalName}}() *cobra.Command {
cmd := &cobra.Command{}

{{- $useJsonForAllFields := or .IsJsonOnly (and .Request (or (not .Request.IsAllRequiredFieldsPrimitive) .Request.HasRequiredNonBodyField)) -}}
{{- $needJsonFlag := or $useJsonForAllFields (and .Request (not .Request.IsOnlyPrimitiveFields)) -}}
{{- $needJsonFlag := or .CanSetRequiredFieldsFromJson (and .Request (not .Request.IsOnlyPrimitiveFields)) -}}

{{- if .Request}}

Expand Down Expand Up @@ -143,7 +142,7 @@ func new{{.PascalName}}() *cobra.Command {
{{if $hasRequiredArgs }}
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs({{len .Request.RequiredFields}})
{{- if $useJsonForAllFields }}
{{- if .CanSetRequiredFieldsFromJson }}
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
Expand All @@ -162,7 +161,7 @@ func new{{.PascalName}}() *cobra.Command {
if err != nil {
return err
}
}{{end}}{{if $useJsonForAllFields }} else {
}{{end}}{{if .CanSetRequiredFieldsFromJson }} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What threw me off here when reading this is, is that this check really pertains to the previous block. I.e. if . CanSetRequiredFieldsFromJson and cmd.Flags().Changed("json"), then we don't want to bother 1) prompting for an ID, or 2) checking the # of args.

I know this is a rename so it is no different from what it was, but please add a comment describing why we need this statement + else branch. It's rather daunting at the moment.

{{- end }}
{{- if $hasIdPrompt}}
if len(args) == 0 {
Expand Down Expand Up @@ -196,7 +195,7 @@ func new{{.PascalName}}() *cobra.Command {
{{- else -}}
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
{{- end -}}
{{if $useJsonForAllFields }}
{{if .CanSetRequiredFieldsFromJson }}
}
{{end }}
{{end}}
Expand Down
33 changes: 16 additions & 17 deletions cmd/account/groups/groups.go

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

33 changes: 16 additions & 17 deletions cmd/account/service-principals/service-principals.go

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

33 changes: 16 additions & 17 deletions cmd/account/users/users.go

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

6 changes: 1 addition & 5 deletions cmd/workspace/catalogs/catalogs.go

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

6 changes: 1 addition & 5 deletions cmd/workspace/external-locations/external-locations.go

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

33 changes: 16 additions & 17 deletions cmd/workspace/groups/groups.go

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

33 changes: 16 additions & 17 deletions cmd/workspace/pipelines/pipelines.go

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

37 changes: 14 additions & 23 deletions cmd/workspace/providers/providers.go

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

33 changes: 16 additions & 17 deletions cmd/workspace/recipients/recipients.go

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

Loading