Documentation
¶
Overview ¶
Package cli generates a kong command line from an operation registry.
Each operation's CLI path ("note <id> delete") becomes nested kong commands built with reflect.StructOf. Input fields keep their own kong tags, so a field is declared once for the CLI and the wire. A path placeholder (<id>) becomes a branching positional argument and fills the input field with that json name. Root flags declared in Options.Globals with a json tag fill the input field with the same json name, so `tool --limit 5 notes list` and `tool notes list --limit 5` both work.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run parses args, runs the selected operation or command and returns the process exit code. It never calls os.Exit.
func Validate ¶
Validate builds the command tree without running it, so a tool's tests catch a declaration kong rejects, such as a duplicate flag. It also rejects a command flag that kong accepts but would never deliver: one that reuses the name, an alias or the short form of a root flag (--json, --agent, --fields, --yes, --version, --help or one of the tool's Globals), and an operation flag named --apply or --dry-run. Run does not repeat this check, so a tool that already ships such a flag keeps running.
Types ¶
type Command ¶
Command is a hand-written kong command. Cmd is a pointer to a kong command struct whose Run method takes a *Context.
type Context ¶
type Context struct {
context.Context
Registry *op.Registry
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
// JSON reports whether the caller asked for machine output (--json or
// --agent).
JSON bool
}
Context is what a hand-written command's Run method receives.
type Options ¶
type Options struct {
// Description is the root help text.
Description string
// Globals is an optional pointer to a struct of root flags. A field with a
// json tag fills the operation input field with the same json name and
// type whenever the flag is given on the command line; otherwise the
// input's own default applies, as it does over HTTP and MCP. Fields
// without a json tag are root flags the tool reads itself.
Globals any
// Commands are hand-written commands mounted next to the operations, for
// the few actions that do not fit the registry.
Commands []Command
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
}
Options configures the generated command line.