Documentation
¶
Overview ¶
Package spec loads commands.json, the single definition of every Droidline command, and normalises raw requests against it.
Index ¶
- func Raw() []byte
- type Alias
- type ArgError
- type Command
- type Cut
- type ErrorDef
- type Field
- type I18n
- type Param
- type Returns
- type Selector
- type Spec
- func (s *Spec) Command(name string) (c *Command, by string)
- func (s *Spec) CutsNetwork(c *Command, params map[string]any) bool
- func (s *Spec) Error(code string) *ErrorDef
- func (s *Spec) IsSelector(by string) bool
- func (s *Spec) Names() []string
- func (s *Spec) Normalize(name string, raw map[string]any) (*Command, map[string]any, error)
- func (s *Spec) ParseArg(p *Param, raw string) (any, error)
- func (s *Spec) RenderError(code, lang string, fields map[string]any) string
- func (s *Spec) SelectorNames() []string
- func (s *Spec) Similar(name string, n int) []string
- func (s *Spec) SortedErrorCodes() []string
- type TypeDef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Command ¶
type Command struct {
Name string `json:"name"`
Group string `json:"group"`
Phase int `json:"phase"`
Scope string `json:"scope"`
Requires []string `json:"requires,omitempty"`
Condition bool `json:"condition,omitempty"`
Macro bool `json:"macro,omitempty"`
CutsNetwork *Cut `json:"cuts_network,omitempty"`
Summary I18n `json:"summary"`
Notes I18n `json:"notes,omitempty"`
Params []Param `json:"params"`
Returns Returns `json:"returns"`
Errors []string `json:"errors,omitempty"`
Aliases []Alias `json:"aliases,omitempty"`
SDKSave string `json:"sdk_save,omitempty"`
MCP *bool `json:"mcp,omitempty"`
MinSDK int `json:"min_sdk,omitempty"`
Example string `json:"example,omitempty"`
Examples []string `json:"examples,omitempty"`
}
type Param ¶
type Param struct {
Ref string `json:"ref,omitempty"`
Name string `json:"name"`
Type string `json:"type"`
Required bool `json:"required,omitempty"`
Default any `json:"default,omitempty"`
Enum []string `json:"enum,omitempty"`
Unit string `json:"unit,omitempty"`
ClientOnly bool `json:"client_only,omitempty"`
Doc I18n `json:"doc,omitempty"`
}
type Spec ¶
type Spec struct {
Proto int `json:"proto"`
Selectors []Selector `json:"selectors"`
CommonParams map[string]Param `json:"common_params"`
Errors []ErrorDef `json:"errors"`
Commands []*Command `json:"commands"`
BatchOnly []*Command `json:"batch_only"`
Types map[string]TypeDef `json:"types"`
// contains filtered or unexported fields
}
func MustLoad ¶
func MustLoad() *Spec
MustLoad is Load for package init paths where a broken embed is a build bug.
func (*Spec) CutsNetwork ¶
CutsNetwork reports whether this normalised call will drop the phone's link.
func (*Spec) IsSelector ¶
func (*Spec) Normalize ¶
Normalize checks raw request fields against the command definition and returns the parameters the agent (or server handler) receives: aliases resolved, positional args mapped, values coerced, defaults filled, client-only params dropped.
func (*Spec) ParseArg ¶
ParseArg converts one command-line string into the JSON value a param expects.
func (*Spec) RenderError ¶
RenderError fills the message template of code in lang. Fields the template needs but the caller did not supply render as "?".
func (*Spec) SelectorNames ¶
func (*Spec) Similar ¶
Similar returns up to n command or alias names close to name, for "did you mean".
func (*Spec) SortedErrorCodes ¶
SortedErrorCodes is used by generators and docs that want a stable order.