Skip to content
Open
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
2 changes: 2 additions & 0 deletions internal/cligen/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type MethodJSON struct {
IsJsonOnly bool `json:"is_json_only,omitempty"`
IsCrudCreate bool `json:"is_crud_create,omitempty"`
IsCrudRead bool `json:"is_crud_read,omitempty"`
IsCrudUpdate bool `json:"is_crud_update,omitempty"`
IsHiddenCLI bool `json:"is_hidden_cli,omitempty"`
IsResponseByteStream bool `json:"is_response_byte_stream,omitempty"`
HasRequiredPositionalArguments bool `json:"has_required_positional_arguments,omitempty"`
Expand Down Expand Up @@ -192,6 +193,7 @@ type FieldJSON struct {
IsQuery bool `json:"is_query,omitempty"`
IsComputed bool `json:"is_computed,omitempty"`
IsOutputOnly bool `json:"is_output_only,omitempty"`
IsImmutable bool `json:"is_immutable,omitempty"`
IsRequestBodyField bool `json:"is_request_body_field,omitempty"`
IsOptionalObject bool `json:"is_optional_object,omitempty"`

Expand Down
9 changes: 8 additions & 1 deletion internal/cligen/templates/service.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ func new{{.PascalName}}() *cobra.Command {
{{else if .Entity.MapValue }}// TODO: map via StringToStringVar: {{.Name}}
{{else if .IsComputed -}}
{{else if .IsOutputOnly -}}
{{- /* Immutable (create-only) fields are settable at create but cannot
change on update. They keep their flag on create-type commands
(and any non-update command) and are omitted from update-type
commands. Computed/output-only fields are handled above and stay
flagless everywhere, so a field that is both immutable and
computed (e.g. dashboards parent_path) is unaffected by this. */ -}}
{{else if and .IsImmutable $method.IsCrudUpdate -}}
{{else if .Entity.Enum }}cmd.Flags().Var(&{{- template "request-body-obj" (dict "Method" $method "Field" .)}}, "{{.KebabName}}", `{{.Summary | without "`" | trimSuffix "."}}{{if .Summary}}. {{end}}Supported values: {{template "printArray" .Entity.Enum}}{{if $hasFieldMask}}. Wire name: '{{.Name}}'.{{end}}`)
{{else if or .Entity.IsDuration .Entity.IsTimestamp .Entity.IsFieldMask}} var {{.CamelName}}Param string
cmd.Flags().StringVar(&{{.CamelName}}Param, "{{.KebabName}}", {{.CamelName}}Param, `{{.Summary | without "`" | trimSuffix "."}}{{if .Summary}}.{{end}}{{if $hasFieldMask}} Wire name: '{{.Name}}'.{{end}}`)
Expand Down Expand Up @@ -403,7 +410,7 @@ func new{{.PascalName}}() *cobra.Command {
{{- template "args-scan" (dict "Arg" $arg "Field" $field "Method" $method "HasIdPrompt" $hasIdPrompt "ExcludeFromJson" $excludeFromJson)}}
{{- end -}}
{{- range .AllFields -}}
{{- if and (not .Required) (not .IsComputed) (not .IsOutputOnly)}}
{{- if and (not .Required) (not .IsComputed) (not .IsOutputOnly) (not (and .IsImmutable $method.IsCrudUpdate))}}
{{if or .Entity.IsDuration .Entity.IsTimestamp .Entity.IsFieldMask}}
if {{.CamelName}}Param != "" {
{{template "parse-well-known-type" (dict "Method" $method "Field" . "SourceValue" (printf "%sParam" .CamelName))}}
Expand Down
2 changes: 2 additions & 0 deletions internal/cligen/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func fromMethod(m *clijson.MethodJSON) *MethodJSON {
IsJsonOnly: m.IsJsonOnly,
IsCrudCreate: m.IsCrudCreate,
IsCrudRead: m.IsCrudRead,
IsCrudUpdate: m.IsCrudUpdate,
IsHiddenCLI: m.IsHiddenCLI,
IsResponseByteStream: m.IsResponseByteStream,
HasRequiredPositionalArguments: m.HasRequiredPositionalArguments,
Expand Down Expand Up @@ -161,6 +162,7 @@ func fromField(f *clijson.FieldJSON) *FieldJSON {
IsQuery: f.IsQuery,
IsComputed: f.IsComputed,
IsOutputOnly: f.IsOutputOnly,
IsImmutable: f.IsImmutable,
IsRequestBodyField: f.IsRequestBodyField,
IsOptionalObject: f.IsOptionalObject,
Entity: fromEntity(f.Entity),
Expand Down
15 changes: 10 additions & 5 deletions internal/clijson/types.go

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

Loading