cli

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 5 Imported by: 0

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

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) Add

func (r *Registry) Add(c contracts.Cmd) error

Add registers a command. It rejects an empty path or a duplicate path.

func (*Registry) Dispatch

func (r *Registry) Dispatch(ctx context.Context, args []string) (string, error)

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) Help

func (r *Registry) Help() string

Help renders one usage line per command, sorted by path, for the root help.

func (*Registry) Intercept added in v0.6.5

func (r *Registry) Intercept(prefix []string, wrap func(cmd contracts.Cmd, next Runner) Runner)

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

func (r *Registry) Run(ctx context.Context, path []string, in contracts.Input) (string, error)

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.

type Runner added in v0.6.5

type Runner func(context.Context, contracts.Input) (string, error)

Runner is a command's handler, named so a caller can wrap one.

Jump to

Keyboard shortcuts

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