Documentation
¶
Overview ¶
Package spec loads commands.json, the single definition of every Droidline command, and normalises raw requests against it.
Index ¶
- func CheckQuery(v any) (map[string]any, error)
- func DescribeQuery(q map[string]any) string
- func MatchField(by, value string, n *Node) bool
- func QueryKeys() []string
- func Raw() []byte
- type Alias
- type ArgError
- type Command
- type Cut
- type ErrorDef
- type Field
- type I18n
- type Node
- type Param
- type QueryDef
- 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 ¶
func CheckQuery ¶ added in v0.1.1
CheckQuery validates a query object and returns a copy with bounds as int64.
func DescribeQuery ¶ added in v0.1.1
DescribeQuery is the target text used in NOT_FOUND and friends.
func MatchField ¶ added in v0.1.1
MatchField applies one simple selector (by, value) to a node.
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"`
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"`
SDKWrap string `json:"sdk_wrap,omitempty"`
SDKManual bool `json:"sdk_manual,omitempty"`
// RunsOn "server" marks a phone command the PC carries out itself, using screenshots and taps.
RunsOn string `json:"runs_on,omitempty"`
MCP *bool `json:"mcp,omitempty"`
// MCPOptIn keeps a tool out of the MCP server unless --tools names it.
MCPOptIn bool `json:"mcp_opt_in,omitempty"`
MinSDK int `json:"min_sdk,omitempty"`
Example string `json:"example,omitempty"`
Examples []string `json:"examples,omitempty"`
}
type Node ¶ added in v0.1.1
Node is one element of a dump tree, linked to its parent.
func FindAll ¶ added in v0.1.1
FindAll returns the nodes a selector matches: by is a selector name with a value, or a query object. Directional queries come back nearest first.
func RowOf ¶ added in v0.1.1
RowOf is the row the row key compares against; the inspector uses it to suggest selectors.
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 QueryDef ¶ added in v0.1.1
type QueryDef struct {
Doc I18n `json:"doc"`
Keys []struct {
Key string `json:"key"`
Type string `json:"type"`
Doc I18n `json:"doc"`
} `json:"keys"`
}
QueryDef documents the keys a query object accepts; spec/query.go implements them.
type Spec ¶
type Spec struct {
Proto int `json:"proto"`
Selectors []Selector `json:"selectors"`
Query QueryDef `json:"query"`
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.