Documentation
¶
Overview ¶
Package cmdutil provides the generic Build function for constructing SDK-backed CLI subcommands with consistent flags and protocol enforcement.
Every namespace subcommand follows the same contract:
- Optional --json flag accepts a raw JSON payload
- Optional --output flag (json | ndjson | text)
- Optional --dry-run flag prints the request without sending it (never requires auth)
- camelCase input keys are transparently normalized to snake_case where the SDK uses snake_case JSON tags (e.g. agentId → agent_id)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶ added in v0.7.0
Build constructs a *cobra.Command from spec, enforcing:
- --json required check (before anything else, when JSONRequired is true)
- Transparent camelCase → snake_case key normalization on --json input
- --dry-run check before SDK init (never requires auth)
- SDK init only when actually sending
- Consistent --json / --output / --dry-run flag registration
Types ¶
type Spec ¶ added in v0.7.0
type Spec[Req any] struct { Use string Short string Long string // JSONRequired causes an error when --json is absent. // Set false for list/read commands where the request body is optional. JSONRequired bool // ErrTransform optionally remaps errors returned by json.Unmarshal before // they are surfaced to the user. Use it to replace Go type names in SDK // enum validation errors with human-readable messages. The transform must // return an error (never nil); return fmt.Errorf("invalid --json: %w", err) // as the fallback to preserve the default behavior. ErrTransform func(err error) error // Run calls the SDK method and returns the response payload to serialize. // The payload must be the inner component field — NOT the operation wrapper // (e.g. return resp.ListCollectionsResponse, not resp). // Return (nil, nil) for operations with no response body (delete, etc.). Run func(ctx context.Context, sdk *glean.Glean, req Req) (any, error) }
Spec describes a single SDK-backed subcommand.
Click to show internal directories.
Click to hide internal directories.