Documentation
¶
Overview ¶
Package cli provides tbd's command dispatcher: a small registry that commands join from their init() functions, plus the Context handed to each handler.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dispatch ¶
Dispatch validates and runs the command named by ctx.Args.Command using the given Context, returning the command's error. Unlike Run it does not touch the process streams or exit code, so a command handler can invoke it to resume a previously interrupted operation (see tbd continue).
Types ¶
type Args ¶
Args and Parse are re-exported from the argv parser library so existing callers keep working while the parsing/validation logic lives in one place.
type Command ¶
type Command struct {
Name string
Summary string
Usage string
Spec argv.Spec
Run func(*Context) error
}
Command is a registered tbd subcommand. Spec declares the options it accepts; the dispatcher validates every invocation against it (merged with the global options), so unknown options get a helpful error instead of being ignored.
type Context ¶
type Context struct {
Args Args
Raw []string // the raw argv tokens this command was invoked with
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
Dir string
IsTTY bool
}
Context carries everything a command handler needs: the parsed arguments, output streams, and the directory from which tbd was invoked.