Documentation
¶
Overview ¶
Package cli is the native, channel-agnostic command dispatcher. It holds declared contracts.Cmd values keyed by their namespace Path and resolves an argv invocation to one. It imports only contracts: a command's Run may close over anything (a gateway client, a backend), but the registry never sees it.
Index ¶
- type Registry
- func (r *Registry) Add(c contracts.Cmd) error
- func (r *Registry) Dispatch(ctx context.Context, args []string) (string, error)
- func (r *Registry) Help() string
- func (r *Registry) Intercept(prefix []string, wrap func(cmd contracts.Cmd, next Runner) Runner)
- func (r *Registry) Run(ctx context.Context, path []string, in contracts.Input) (string, error)
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry collects commands and dispatches argv to them.
func (*Registry) Dispatch ¶
Dispatch resolves args to the command whose Path is the longest prefix of args, parses the remainder into an Input (--flag value pairs into Args; a valueless optional boolean param becomes "true", while an optional ValueRequired param still needs a following value; anything left over goes to Rest), checks required params, and runs it. It returns the handler's output string.
func (*Registry) Intercept ¶ added in v0.6.5
Intercept wraps the handler of every registered command whose Path starts with prefix. wrap receives the command as declared and its current handler, and returns the handler to run in its place; returning next leaves the command untouched. Commands added afterwards are not wrapped, so a caller installs its interceptors once the registry is complete.
func (*Registry) Run ¶
Run invokes the command at an exact path with a pre-built Input, skipping argv parsing. It is the typed seam for programmatic callers (e.g. the hub's typed SessionControl methods) so they never assemble stringly-typed flag argv that could silently drift from the declared params. Required params are still checked, so a typed caller gets the same validation as the CLI.