dynamic

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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")

	ErrMissingArguments = errors.New("missing argument")

	ErrTooManyArguments = errors.New("too many arguments")
)

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

A service split by function into subpackages adds one level, named after the subpackage, because that is how its contracts, its Go import paths and its TypeScript namespaces are named too:

leaflow <service> <subpackage> <operation-id>
leaflow billing   catalog      list-prices

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

Bind adds the shell's half to the contract's parameter split: a flag name for every query parameter, and one flag per scalar body field.

The split itself comes from the contract and is shared with every other caller; what is here is only what a shell needs, because a shell is the one caller that cannot type an object.

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