gcloud

package
v0.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package gcloud provides a code generator for gcloud commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(model *api.API, outdir string) error

Generate is the package entry point. It builds the model, renders main.go, writes it, then renders any other generated files via language.GenerateFromModel.

Types

type CLIModel added in v0.12.0

type CLIModel struct {
	// Imports holds the Go imports rendered into the generated main.go.
	Imports []Import

	// Groups holds the top-level gcloud command groups rendered into main.go.
	Groups []Group
}

CLIModel represents the data structure for the template.

type ClientCall added in v0.12.1

type ClientCall struct {
	// Method is the unqualified client method to call on the constructed
	// client, for example "GetInstance". The template invokes it as
	// `client.<Method>(ctx, &<RequestType>{...})`.
	Method string

	// NameField is the field on the request message that takes the
	// composed resource path, for example "Name" for AIP-131 Get requests.
	// The template assigns it from the local path variable.
	NameField string

	// Package is the import alias of the Go client package, for example
	// "parallelstore". The template invokes the constructor as
	// `client, err := <Package>.NewClient(ctx)`.
	Package string

	// RequestType is the qualified request message type, for example
	// "parallelstorepb.GetInstanceRequest". The template composites a
	// literal of this type and passes its address to the method.
	RequestType string
}

ClientCall describes a Go client method invocation that should replace the default print-only action for a generated command.

type Command

type Command struct {
	Args       []string
	ClientCall *ClientCall
	Flags      []Flag
	Name       string
	PathFormat string
	PathLabel  string
	Usage      string
}

Command represents a leaf command.

func (Command) HasPath added in v0.12.1

func (c Command) HasPath() bool

HasPath reports whether the command composes a resource path.

func (Command) PathFormatArgs added in v0.12.1

func (c Command) PathFormatArgs() string

PathFormatArgs returns the comma-separated cmd.String("X") arguments passed to the generated fmt.Sprintf call.

type Flag added in v0.12.1

type Flag struct {
	// Name is the long flag name without leading dashes (e.g. "project").
	Name string

	// Kind is the urfave/cli flag type (e.g. "String", "Bool").
	Kind string

	// Required reports whether the flag must be set on the command line.
	Required bool

	// Usage is the help text shown next to the flag.
	//
	// TODO(https://github.com/googleapis/librarian/issues/5769):
	// Usage is currently a generic "The <name>." string. Source it from
	// the proto field's documentation when we wire that through.
	Usage string
}

Flag represents a single CLI flag.

type Group added in v0.12.0

type Group struct {
	Name      string
	Usage     string
	Subgroups []Subgroup
	Commands  []Command
}

Group represents a gcloud command group.

type Import added in v0.12.1

type Import struct {
	// Alias is the optional package alias; empty when the import has no
	// alias. For example, "parallelstore" in:
	//
	//	parallelstore "cloud.google.com/go/parallelstore/apiv1"
	Alias string

	// Path is the import path of the package, for example
	// "cloud.google.com/go/parallelstore/apiv1".
	Path string
}

Import represents a Go import line in the generated main.go.

type Subgroup added in v0.12.0

type Subgroup struct {
	Name     string
	Usage    string
	Commands []Command
}

Subgroup represents a nested command group.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL