Help us shape the future of Go! Take the 2026 Go Developer Survey

commands

package
v0.0.0-...-a92561a Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package commands owns command-catalog algorithms that are independent of Bubble Tea, plugin execution, and the CLI model.

Index

Constants

View Source
const MaxHistoryEntries = 1000

MaxHistoryEntries bounds persisted interactive input history.

Variables

This section is empty.

Functions

func AppendHistory

func AppendHistory(entry string)

AppendHistory adds one non-empty entry to persistent history.

func ApplySuggestion

func ApplySuggestion(input string, aliases map[string]string) string

ApplySuggestion turns a selected display value into a command input.

func BuiltInAliases

func BuiltInAliases() map[string]string

BuiltInAliases returns aliases for built-in commands.

func BuiltInCategories

func BuiltInCategories() map[string]string

BuiltInCategories returns the presentation category for built-in commands. Unknown commands intentionally fall back to Other so plugin commands remain usable without requiring a change to rho's catalog.

func BuiltInDescriptions

func BuiltInDescriptions() map[string]string

BuiltInDescriptions returns the help text for built-in commands.

func BuiltInNames

func BuiltInNames() []string

BuiltInNames returns the command names that are always available in rho. Dynamic plugin and subcommand names are supplied by the composition root.

func Category

func Category(name string) string

Category returns the stable display category for a command name.

func HistoryPath

func HistoryPath() string

HistoryPath returns the persistent input-history path.

func LoadHistory

func LoadHistory() []string

LoadHistory loads history, returning an empty slice when no file exists.

func SaveHistory

func SaveHistory(history []string)

SaveHistory deduplicates entries, keeps the last occurrence, and persists at most MaxHistoryEntries entries in chronological order.

func SuggestTypo

func SuggestTypo(typo string, commandNames []string) string

SuggestTypo returns the closest known command when the edit distance is a plausible typo rather than a different word.

func Suggestions

func Suggestions(input string, commandNames []string, descriptions, aliases map[string]string) []string

Suggestions returns matching command names with descriptions and aliases.

func ValidateBuiltIns

func ValidateBuiltIns() error

ValidateBuiltIns checks the command metadata that powers completion and help. Keeping this invariant in the feature package prevents the CLI from advertising commands without descriptions or aliases pointing at commands that do not exist.

Types

type ParsedInput

type ParsedInput struct {
	Text    string
	Parts   []string
	Command string
}

ParsedInput is the normalized command input consumed by a CLI dispatcher.

func Parse

func Parse(text string) ParsedInput

Parse normalizes the supported help shorthand and tokenizes command input. It deliberately does not resolve aliases or execute commands.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry owns canonical names, aliases, collision policy, and deterministic enumeration. Frontends attach their own typed handlers to these specs.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) All

func (r *Registry) All() []Spec

func (*Registry) Lookup

func (r *Registry) Lookup(name string) (Spec, bool)

func (*Registry) Names

func (r *Registry) Names() []string

func (*Registry) Register

func (r *Registry) Register(spec Spec) bool

func (*Registry) Size

func (r *Registry) Size() int

type Resolution

type Resolution struct {
	Parsed     ParsedInput
	Command    string
	Name       string
	IsSlash    bool
	Namespaced bool
}

Resolution is the pure routing decision made before a live command handler is consulted. Handler lookup remains a composition-root concern.

func Resolve

func Resolve(parsed ParsedInput, aliases map[string]string) Resolution

Resolve applies aliases and derives the canonical registry key without executing or looking up a command.

type Spec

type Spec struct {
	Name        string
	Aliases     []string
	Description string
	Usage       string
}

Spec is command metadata independent of any UI or handler implementation.

Jump to

Keyboard shortcuts

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