registry

package
v1.13.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Distance

func Distance(a, b string) int

Distance is the Levenshtein edit distance between a and b. It backs the "did you mean --x?" suggestions for unknown flags and unknown :help <command> names. Kept here so both the api (validation) and command (help) packages can use it without an import cycle.

func Register

func Register(cmd Command)

Register a new command. Must only be called from init() functions.

func Suggest

func Suggest(prefix string) []string

Suggest returns all command names that start with a given prefix

Types

type Aliaser

type Aliaser interface {
	AliasOf() string
}

Aliaser is optionally implemented by alias commands to indicate which primary command they delegate to.

type Command

type Command interface {
	Name() string
	Description() string
	Execute(ctx any, args args.Args) tea.Cmd
}

func All

func All() []Command

All returns a slice of all registered api

func Get

func Get(name string) (Command, bool)

Get returns a command by name

type CommandSpec

type CommandSpec struct {
	// Usage is the positional usage, e.g. "[command]" or "" for none.
	Usage string
	// Detail is optional prose rendered under USAGE — explain modes,
	// e.g. that running with no flags starts an interactive flow.
	Detail string
	// Flags is the accepted-flag allow-list for strict validation.
	Flags []FlagSpec
	// Examples are full example invocations, incl. the leading ':'.
	Examples []string

	// Passthrough disables both help interception and strict flag
	// validation for this command: every argument reaches Execute
	// unchanged. Intended only for delegating/unavailable stubs (e.g.
	// the OSS bootstrap stub) that must keep their own messaging and
	// must not document Pro internals in the OSS repo.
	Passthrough bool
}

CommandSpec is the optional, declarative documentation/validation contract for a command. Commands expose it via CommandWithSpec.

func SpecOf

func SpecOf(cmd Command) (CommandSpec, bool)

SpecOf resolves a command's spec, following Aliaser → primary so an alias transparently inherits its target's documentation and validation rules.

type CommandWithAliases

type CommandWithAliases struct {
	Command
	Aliases []string
}

CommandWithAliases pairs a primary command with its collected alias names.

func PrimaryCommands

func PrimaryCommands() []CommandWithAliases

PrimaryCommands returns deduplicated commands with alias names collected. Commands implementing Aliaser are folded into their target's Aliases slice.

type CommandWithSpec

type CommandWithSpec interface {
	Spec() CommandSpec
}

CommandWithSpec is the optional capability interface. It mirrors the Aliaser pattern: discovered via type assertion, additive and non-breaking across the swarmcli ↔ swarmcli-be module boundary.

type FlagSpec

type FlagSpec struct {
	Name        string // long flag, without leading "--" (e.g. "node-id")
	Short       string // optional single-char alias without "-"; "" = none
	TakesValue  bool   // false ⇒ boolean (--force); true ⇒ --host <value>
	Placeholder string // usage value placeholder, e.g. "<host>"; used only if TakesValue
	Description string
}

FlagSpec declares a single flag a command accepts. It drives both the per-command help screen and strict unknown-flag validation.

Jump to

Keyboard shortcuts

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