tree

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 12 Imported by: 47

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoop            = errors.New("noop")
	ErrInvalidCommand  = errors.New("invalid command")
	ErrMissingCommand  = errors.New("missing command")
	ErrMissingArgument = errors.New("missing argument")
)

Functions

This section is empty.

Types

type Arg

type Arg struct {
	Name        string
	Description string
	Repeat      bool
	Optional    bool
	Suggest     func(ctx context.Context, t Root, r *readline.Readline) []goprompt.Suggest
}

type ArgInfo added in v0.21.0

type ArgInfo struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Optional    bool   `json:"optional,omitempty"`
	// Repeat marks an argument that may be given more than once. Only the last
	// argument of a command can repeat.
	Repeat bool `json:"repeat,omitempty"`
}

ArgInfo describes a single positional argument of a command, in the order it is expected on the command line.

type Args

type Args []*Arg

func (Args) Last

func (a Args) Last() *Arg

func (Args) Validate added in v0.4.0

func (a Args) Validate(args readline.Args) error

type CommandInfo added in v0.21.0

type CommandInfo struct {
	// FullPath is the command as typed, e.g. "cache clear".
	FullPath    string `json:"full_path"`
	Description string `json:"description"`
	// Dynamic marks a node whose name is resolved at runtime (a cluster name,
	// a cache key, ...). Its FullPath carries a "<placeholder>" instead of a
	// literal name - run the command to discover the actual values.
	Dynamic     bool          `json:"dynamic,omitempty"`
	Arguments   []ArgInfo     `json:"arguments,omitempty"`
	Flags       []FlagInfo    `json:"flags,omitempty"`
	Subcommands []CommandInfo `json:"subcommands,omitempty"`
}

CommandInfo describes one command for the `posh agent catalog` catalog. It mirrors the shape used by other agent-facing CLIs, so a consumer that can read one catalog can read this one.

func (CommandInfo) Usage added in v0.21.0

func (c CommandInfo) Usage() string

Usage renders the arguments as a usage string, e.g. "[Key] <Value>...", where required arguments are bracketed, optional ones angled and a repeatable argument is suffixed with "...".

type FlagInfo added in v0.21.0

type FlagInfo struct {
	Name        string `json:"name"`
	Shorthand   string `json:"shorthand,omitempty"`
	Type        string `json:"type"`
	Default     string `json:"default"`
	Description string `json:"description"`
}

FlagInfo describes a single flag of a command.

type Node

type Node struct {
	Name        string
	Values      func(ctx context.Context, r *readline.Readline) []goprompt.Suggest
	Args        Args
	Flags       func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error
	Description string
	Nodes       []*Node
	Execute     func(ctx context.Context, r *readline.Readline) error
}

type Nodes

type Nodes []*Node

type Root

type Root interface {
	Node() *Node
	Describe(ctx context.Context) CommandInfo
	Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest
	Execute(ctx context.Context, r *readline.Readline) error
	Help(ctx context.Context, r *readline.Readline) string
}

func New added in v0.4.0

func New(node *Node) Root

Jump to

Keyboard shortcuts

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