cmdmeta

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cmdmeta is the command-surface vocabulary AND the per-value validation engine over it, shared by the operation catalog and the command descriptors: value kinds, the flag and positional shapes, sections, response-field hints, auth, the safety classification, and NormalizeValue/CoerceValue (validate one value against its kind). Its only internal dependency is internal/output (the error taxonomy, a stdlib-only leaf), so any layer can describe AND validate a command surface without pulling in a routing or execution dependency. The cross-field rules that span several params of one operation live with the operations that own them (internal/ops), not here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoerceValue

func CoerceValue(p Param, v any, label string) (raw string, present bool, err error)

CoerceValue applies the per-kind TYPE rules to an already-present, non-null value decoded to a Go any (bool | int64 | float64 | string | []any), and returns the raw string NormalizeValue then validates — exactly as a CLI flag string would be. It is the shared core behind the frontends whose inputs are typed values rather than already-string flags. Source-specific null/undefined detection stays in the caller; present=false means "treat as omitted" (a null/undefined value handled by the caller, or a false flag).

It owns the money guardrail: a decimal given a number rather than a string is rejected HERE, before any request is built — so no frontend can let a float into price/qty/amount.

func NormalizeValue

func NormalizeValue(p Param, raw, label string) (string, error)

NormalizeValue validates and normalizes one raw flag/positional value per its param, returning the value to send (API form). label is the user-facing name used in error messages, e.g. `--price`.

func ParseDuration

func ParseDuration(value string) (d time.Duration, ok bool)

ParseDuration parses a Go duration string (time.ParseDuration — units ms, s, m, h, and combinations like "1h30m"). ok is false on a malformed string; callers apply their own range check.

Types

type Auth

type Auth struct {
	Permission string
}

Auth describes the signing requirement of an endpoint. A nil *Auth means the endpoint is public. Permission == "" means signed with any key; a non-empty Permission names the API permission the key must hold.

type Param

type Param struct {
	// Flag is the CLI flag name without leading dashes (kebab-case).
	Flag string
	// API is the Korbit parameter name the value is sent as.
	API  string
	Kind ValueKind
	Desc string

	Required    bool
	EnumValues  []string
	Min         *int
	Max         *int
	Pattern     *regexp.Regexp
	PatternDesc string
	Default     string
	// Experimental marks a flag belonging to an opt-in, not-yet-stable feature
	// (gated behind --enable-experimental). Plain `--help` hides it; help shown
	// with --enable-experimental reveals it. The machine catalog always publishes
	// it (with this bit set) so agents can still discover it.
	Experimental bool
}

Param is a single flag a command accepts.

type Positional

type Positional struct {
	Name     string
	API      string
	Kind     ValueKind
	Desc     string
	Required bool
	Variadic bool
}

Positional is a positional argument.

type ResponseField

type ResponseField struct {
	Name string
	Type string
	Desc string
}

ResponseField is one machine-readable success-response field hint for an endpoint: top-level fields, and for an array response the element's fields.

type Safety

type Safety string

Safety classifies an operation's retry/idempotency posture, the basis for the call policy the operation layer derives.

const (
	// SafetyReadOnly is a read (GET): retry-safe, no side effect.
	SafetyReadOnly Safety = "readOnly"
	// SafetyIdempotent is a non-GET write that is safe to send more than once
	// with no extra effect (a cancel, or an address generate that returns the
	// existing address).
	SafetyIdempotent Safety = "idempotent"
	// SafetyNonIdempotent is a money-moving write with no natural idempotency: it
	// is never blindly resent.
	SafetyNonIdempotent Safety = "nonIdempotent"
)

type Section

type Section string

Section groups commands in help and the catalog.

const (
	SectionMarket  Section = "market"
	SectionOrders  Section = "orders"
	SectionAccount Section = "account"
	SectionFunding Section = "funding"
	SectionKeys    Section = "keys"
	SectionMeta    Section = "meta"
)

type ValueKind

type ValueKind string

ValueKind is the type of a flag or positional value. It drives validation.

const (
	KindString   ValueKind = "string"
	KindInt      ValueKind = "int"
	KindDecimal  ValueKind = "decimal"
	KindEnum     ValueKind = "enum"
	KindSymbol   ValueKind = "symbol"
	KindSymbols  ValueKind = "symbols"
	KindCurrency ValueKind = "currency"
	KindCSV      ValueKind = "csv"
	KindMs       ValueKind = "ms"
	KindDuration ValueKind = "duration"
	KindFlag     ValueKind = "flag"
)

Jump to

Keyboard shortcuts

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