Documentation ¶
Overview ¶
Package subcom is a somewhat easy subcommand runner.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyArgs is returned if an empty args slice was passed to // Cdr.Call. ErrEmptyArgs = errors.New("empty args") // ErrNotFound is returned by Cdr.Call if args[0] didn't have a // registered Handler. ErrNotFound = errors.New("command not found") )
Functions ¶
Types ¶
type Cdr ¶
type Cdr[T any] struct { // contains filtered or unexported fields }
Cdr holds and calls (sub)commands. Cdr's methods are safe for concurrent use by multiple goroutines.
func New ¶
New returns a new Subcommander, ready for use. If any Specs are provided the new Cdr will contain them. specs may be nil.
func (*Cdr[T]) Add ¶
Add adds a single Handler to c. If handler is nil and c has a Handler with the given name, the Handler will be deleted.
func (*Cdr[T]) Call ¶
Call calls a command registered with the Subcommander. The command name is assumed to be args[0]; the name will be appended to parents and removed from he args passed to the CommandHandler. If the comand wasn't found, ErrNotFound is returned. Parents will not be modified by Call, at the cost of an allocation and copy. A subslice of args will be passed to the CommandHandler; it will never be nil.