dynamic

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 19 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, ext *extension.Context) []*cobra.Command

Build assembles the command tree straight from the contracts:

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

Both name parts are literal values 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 the same identifier rather than a second vocabulary that has to be kept in sync with it.

It also means one identifier serves the CLI, the SDKs and an MCP tool name, so a new backend operation becomes reachable everywhere at once, with no table to update.

Commands written in code are layered on top and may replace any of these; see package extension.

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