Skip to content

feat(internal/sidekick/gcloud): add support for create commands#5890

Open
julieqiu wants to merge 1 commit into
googleapis:mainfrom
julieqiu:add-gcloud-create-command
Open

feat(internal/sidekick/gcloud): add support for create commands#5890
julieqiu wants to merge 1 commit into
googleapis:mainfrom
julieqiu:add-gcloud-create-command

Conversation

@julieqiu
Copy link
Copy Markdown
Member

@julieqiu julieqiu commented May 7, 2026

Add support for AIP-133 Create methods. The generated action composes the parent path, builds the resource body from CLI flags, calls the client method, waits for completion when the call is an LRO, and prints the returned resource via protojson.

Enums, maps, repeated fields, nested messages, and fields are skipped with TODOs in the generated code for now.

For #5769

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements support for AIP-133 Create methods in the sidekick gcloud generator. It updates the ClientCall structure to handle resource body fields, maps scalar fields to CLI flags, and tracks skipped fields with TODO comments. The generator template was updated to produce the necessary Go code for both LRO and non-LRO Create operations. Feedback was provided regarding code duplication in the template logic for Create methods, suggesting a refactor to unify request construction.

Comment thread internal/sidekick/gcloud/templates/package/surface_commands.go.tmpl
@julieqiu julieqiu force-pushed the add-gcloud-create-command branch 2 times, most recently from d31ac8c to c29b1aa Compare May 7, 2026 13:33
Add support for AIP-133 Create methods. The generated action composes
the parent path, builds the resource body from CLI flags, calls the
client method, waits for completion when the call is an LRO, and prints
the returned resource via protojson.

Enums, maps, repeated fields, nested messages, and fields are skipped
with TODOs in the generated code and will be implemented in a follow up
PR.
@julieqiu julieqiu force-pushed the add-gcloud-create-command branch from c29b1aa to bd1c47d Compare May 7, 2026 13:42
@julieqiu julieqiu requested a review from coryan May 7, 2026 13:42
@julieqiu julieqiu marked this pull request as ready for review May 7, 2026 13:42
@julieqiu julieqiu requested review from a team as code owners May 7, 2026 13:42
@julieqiu julieqiu enabled auto-merge (squash) May 7, 2026 13:42
Copy link
Copy Markdown
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

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

I don't like the TODOs in the generated output, but if you like them then 🤷 .

{{.Name}}: cmd.{{.Kind}}("{{.Flag}}"),
{{- end}}
{{- range .ClientCall.BodySkippedFields}}
// TODO: {{.}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems odd to output TODO: comments to the generated code? Nobody is going to edit that code to fix them. Maybe just put the TODOs in the generator?

if hasBehavior(f, api.FieldBehaviorIdentifier) {
continue
}
if f.Map {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If anything, the TODOs belong here, no?

}
kind, ok := scalarKind(f.Typez)
if !ok {
call.BodySkippedFields = append(call.BodySkippedFields,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And here.

t.Errorf("mismatch (-want +got):\n%s", diff)
gotCall, gotFlags := buildClientCall(test.method, test.model, test.goClient, test.hasPath)
if diff := cmp.Diff(test.want, gotCall); diff != "" {
t.Errorf("call mismatch (-want +got):\n%s", diff)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something about howwewritego.md and the format of these errors.

// ClientCall describes a Go client method invocation that should replace the
// default print-only action for a generated command.
type ClientCall struct {
// BodyAssignments lists the body's scalar fields that become CLI
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking: how are you planning to deal with fields that are deeply nested in the request "body"? For example:

https://github.com/googleapis/googleapis/blob/c2648728afb6deff882cfc4167a21abd382870fa/google/cloud/secretmanager/v1/service.proto#L322

Uses a "Secret" for the body, which (when using global secrets) requires this field to be set:

https://github.com/googleapis/googleapis/blob/c2648728afb6deff882cfc4167a21abd382870fa/google/cloud/secretmanager/v1/resources.proto#L57

switch t {
case api.TypezString:
return "String", true
case api.TypezInt32:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I assume the UInt* variations are not hard, nor Float and Double...

continue
}
switch f.Typez {
case api.TypezEnum:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You are going to have fun with those.

@coryan coryan disabled auto-merge May 7, 2026 14:15
Copy link
Copy Markdown
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

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

I don't like the TODOs in the generated output, but if you like them then 🤷 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants