cli

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 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) 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.

Jump to

Keyboard shortcuts

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