Skip to content
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
17 changes: 15 additions & 2 deletions .codegen/service.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ var Cmd = &cobra.Command{
{{end}}
// start {{.KebabName}} command

{{if .Request}}var {{.CamelName}}Req {{.Service.Package.Name}}.{{.Request.PascalName}}
{{- $useJsonForAllFields := or .IsJsonOnly (and .Request (or (not .Request.IsAllRequiredFieldsPrimitive) .Request.IsAllRequiredFieldsJsonUnserialisable)) -}}
{{- $needJsonFlag := or $useJsonForAllFields (and .Request (not .Request.IsOnlyPrimitiveFields)) -}}
{{- if .Request}}
var {{.CamelName}}Req {{.Service.Package.Name}}.{{.Request.PascalName}}
{{- if $needJsonFlag}}
var {{.CamelName}}Json flags.JsonFlag
{{- end}}
{{end}}
{{if .Wait}}var {{.CamelName}}SkipWait bool
var {{.CamelName}}Timeout time.Duration{{end}}

Expand All @@ -57,7 +62,9 @@ func init() {
{{.CamelName}}Cmd.Flags().DurationVar(&{{.CamelName}}Timeout, "timeout", {{.Wait.Timeout}}*time.Minute, `maximum amount of time to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state`)
{{end -}}
{{if .Request}}// TODO: short flags
{{- if $needJsonFlag}}
{{.CamelName}}Cmd.Flags().Var(&{{.CamelName}}Json, "json", `either inline JSON string or @path/to/file.json with request body`)
{{- end}}
{{$method := .}}
{{ if not .IsJsonOnly }}
{{range .Request.Fields -}}
Expand Down Expand Up @@ -100,22 +107,26 @@ var {{.CamelName}}Cmd = &cobra.Command{
Annotations: map[string]string{},{{if $hasRequiredArgs }}
Args: func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs({{len .Request.RequiredFields}})
{{- if $useJsonForAllFields }}
if cmd.Flags().Changed("json") {
check = cobra.ExactArgs(0)
}
{{- end }}
return check(cmd, args)
},{{end}}
PreRunE: root.Must{{if .Service.IsAccounts}}Account{{else}}Workspace{{end}}Client,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
{{if .Service.IsAccounts}}a := root.AccountClient(ctx){{else}}w := root.WorkspaceClient(ctx){{end}}
{{- if .Request }}
{{ if $needJsonFlag }}
if cmd.Flags().Changed("json") {
err = {{.CamelName}}Json.Unmarshal(&{{.CamelName}}Req)
if err != nil {
return err
}
} else {
}{{end}}{{if $useJsonForAllFields }} else {
{{- end }}
{{- if $hasIdPrompt}}
if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx)
Expand Down Expand Up @@ -148,7 +159,9 @@ var {{.CamelName}}Cmd = &cobra.Command{
{{- else -}}
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
{{- end -}}
{{if $useJsonForAllFields }}
}
{{end }}
{{end}}
{{if $wait -}}
wait, err := {{if .Service.IsAccounts}}a{{else}}w{{end}}.{{.Service.PascalName}}.{{.PascalName}}(ctx{{if .Request}}, {{.CamelName}}Req{{end}})
Expand Down
36 changes: 6 additions & 30 deletions cmd/account/access-control/access-control.go

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

19 changes: 3 additions & 16 deletions cmd/account/billable-usage/billable-usage.go

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

82 changes: 32 additions & 50 deletions cmd/account/budgets/budgets.go

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

Loading