dynamic

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBodyConflict = errors.New("--body cannot be combined with field flags")

	ErrBodyUnreadable = errors.New("cannot read request body")

	ErrBodyNotJSON = errors.New("--body is not valid JSON")
)

Functions

func Build

func Build(specs *spec.Set, rt *Runtime) []*cobra.Command

Build assembles the command tree straight from the contracts:

leaflow <service> <operation-id>
leaflow compute    create-disk

The name is a literal value from the contract, lowercased and hyphenated. Nothing is inferred, so nothing can drift: an operationId is already treated as a stable identifier — the Go and TypeScript SDKs generate their method names from it — and a command name is now that same identifier rather than a second vocabulary to keep in sync with it. One identifier therefore serves the CLI, the SDKs and an MCP tool name alike.

The contract's tag is not a level in the path. operationIds are unique within a contract, so a tag adds nothing to addressing and quite a lot of noise to typing: `compute disk create-disk` says disk twice. Tags become help groups instead, so `leaflow compute --help` still reads as a set of resources rather than eighty-three flat lines.

Every command comes from a contract. Nothing is hand-written on top: a hand-written command is a second source for the same surface, and then the question "is this one generated" has to be answered per command. Where the contract makes something awkward — a verb that lives in the request body — the fix belongs upstream in the contract, not in a local exception.

func NewCommand

func NewCommand(use string, op *spec.Operation, rt *Runtime) *cobra.Command

Types

type Binding

type Binding struct {
	Operation *spec.Operation

	Path []*openapi3.Parameter

	Query []*openapi3.Parameter

	Body *openapi3.Schema

	Fields []*BodyField
	// contains filtered or unexported fields
}

Binding describes an operation's arguments:

path parameters  -> positional   leaflow compute disk get <disk-id>
query parameters -> flags        --region-code cn-north-1
request body     -> one flag per field, or --body

Path parameters are positional because they are always required and already ordered by the path itself; spelling them as flags only makes the same information longer.

func Bind

func Bind(op *spec.Operation) *Binding

func (*Binding) FlagName

func (b *Binding) FlagName(parameter *openapi3.Parameter) string

func (*Binding) Register

func (b *Binding) Register(cmd *cobra.Command)

func (*Binding) Values

func (b *Binding) Values(cmd *cobra.Command, args []string) (path []string, query map[string][]string, body any, err error)

Values collects what was typed into the three pieces a request needs.

type BodyField

type BodyField struct {
	Name     string
	Flag     string
	Schema   *openapi3.Schema
	Required bool
}

type Runtime

type Runtime struct {
	Client  *transport.Client
	Printer *output.Printer
}

Runtime holds what generated commands need at run time.

It is passed as a pointer because the tree is built before flags are parsed, and --output is not known until after; commands read these fields when they run, not when they are created.

Jump to

Keyboard shortcuts

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