Documentation
¶
Index ¶
- Variables
- type Command
- type CommandDescriptor
- type Node
- type Tree
- func (t *Tree) AddCommand(d CommandDescriptor) *Command
- func (t *Tree) AddShortcut(shortcut, target string) error
- func (t *Tree) AddSubtree(d TreeDescriptor) *Tree
- func (t *Tree) Autocomplete(line string) []string
- func (t *Tree) Commands() []*Command
- func (t *Tree) DisplayHelp(w io.Writer)
- func (t *Tree) DisplayUsage(w io.Writer)
- func (t *Tree) GetHelp(w io.Writer, args []string) error
- func (t *Tree) Lookup(line string) (n Node, args []string, err error)
- func (t *Tree) LookupCommand(line string) (cmd *Command, args []string, err error)
- func (t *Tree) LookupSubtree(line string) (subtree *Tree, args []string, err error)
- func (t *Tree) Parent() *Tree
- func (t *Tree) Subtrees() []*Tree
- type TreeDescriptor
Constants ¶
This section is empty.
Variables ¶
var ( ErrAmbiguous = errors.New("Command is ambiguous") ErrNotFound = errors.New("Command not found") )
Errors returned by the cmd package.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
CommandDescriptor
// contains filtered or unexported fields
}
A Command represents either a single named command or the root of a subtree of commands.
func (*Command) DisplayDescription ¶ added in v0.2.0
DisplayDescription outputs the command's description text. If the command has no description, the commands 'brief' text is output instead.
func (*Command) DisplayHelp ¶ added in v0.2.0
DisplayHelp outputs the help text associated with the command, including its usage, description, and shortcuts.
func (*Command) DisplayShortcuts ¶
DisplayShortcuts displays all shortcuts associated with the command.
func (*Command) DisplayUsage ¶
DisplayUsage outputs the command's usage string.
type CommandDescriptor ¶ added in v0.2.0
type CommandDescriptor struct {
Name string // command name
Brief string // brief description shown in a command list
Description string // long description shown with command help
Usage string // usage hint text
Data any // user-defined data
}
A CommandDescriptor describes a single command within a command tree.
type Node ¶ added in v0.2.0
type Node interface {
DisplayHelp(w io.Writer)
Parent() *Tree
// contains filtered or unexported methods
}
A Node may be a Tree or a Command.
type Tree ¶
type Tree struct {
TreeDescriptor
// contains filtered or unexported fields
}
A Tree contains one or more commands which are grouped together and may be looked up by a shortest unambiguous prefix match.
func NewTree ¶
func NewTree(d TreeDescriptor) *Tree
NewTree creates a new command tree with the given title.
func (*Tree) AddCommand ¶
func (t *Tree) AddCommand(d CommandDescriptor) *Command
AddCommand adds a command to a command tree.
func (*Tree) AddShortcut ¶
AddShortcut adds a shortcut to a command in the tree.
func (*Tree) AddSubtree ¶ added in v0.2.0
func (t *Tree) AddSubtree(d TreeDescriptor) *Tree
AddSubtree adds a child command tree to an existing command tree.
func (*Tree) Autocomplete ¶ added in v0.2.0
Autocomplete builds a list of auto-completion candidates for the provided line of text.
func (*Tree) DisplayHelp ¶
DisplayHelp displays a sorted list of commands (and subtrees) available at the tree's top level.
func (*Tree) DisplayUsage ¶ added in v0.2.0
DisplayUsage outputs the tree's usage string.
func (*Tree) GetHelp ¶ added in v0.2.0
GetHelp parses the 'help' command's arguments string and displays an appropriate help response.
func (*Tree) Lookup ¶
Lookup performs a search on a command tree for a command or subtree node matching the line input. If found, it returns the matching node and the remaining unmatched line arguments.
func (*Tree) LookupCommand ¶ added in v0.2.0
LookupCommand performs a search on a command tree for a command matching the line input. If found, it returns the matching command and the remaining unmatched line arguments.
func (*Tree) LookupSubtree ¶ added in v0.2.0
LookupSubtree performs a search on a command tree for a subtree matching the line input. If found, it returns the matching subtree and the remaining unmatched line arguments.
type TreeDescriptor ¶ added in v0.2.0
type TreeDescriptor struct {
Name string // tree name
Brief string // brief description shown in a command list
Description string // long description shown with command help
Usage string // usage hint text
Data any // user-defined data
}
A TreeDescriptor describes a command tree.