Documentation
¶
Overview ¶
Package tool defines the contract every tool implements.
A tool is a declarative Spec plus a pure function Run(ctx, Request) → Result. The TUI and the CLI build their interface by reading the Spec; no tool writes UI code.
Contract rules:
- Run does no I/O, keeps no global state and honours ctx.
- Reversible tools use a "mode" option (Select) with the values "encode" and "decode".
- Input errors are returned as *InputError; any other error is considered a bug.
- Binary outputs are shown as Base64 or hex depending on the "output" option.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type InputError ¶
InputError is an input error with a position, so the TUI can underline the line and the CLI can report it. Line and Col start at 1; 0 means unknown.
func AsInputError ¶
func AsInputError(err error) (*InputError, bool)
AsInputError extracts an *InputError from err's chain.
func (*InputError) Error ¶
func (e *InputError) Error() string
type Option ¶
type Option struct {
Key, Label, Help string
Kind OptionKind
Choices []string
Min, Max int
Default any
}
type OptionKind ¶
type OptionKind int
const ( Toggle OptionKind = iota // bool Select // one of Choices Number // int within Min/Max String // short text (JWT secret, separator…) )
type OutputKind ¶
type OutputKind int
const ( PlainText OutputKind = iota Highlighted // uses Result.Lang DiffView // uses Result.Diff Matches // uses Result.Spans (regex, JSONPath) Image // Unicode blocks (QR) )
type Span ¶
type Span struct {
Input string // InputSpec key
Start, End int
Group int // 0 = whole match, n = capture group
}
Span is a highlighted range in an input, as byte offsets [Start, End).
type Spec ¶
type Spec struct {
ID string // "base64", "json-format"… (CLI subcommand name)
Name string
Category Category
Description string
Keywords []string
Inputs []InputSpec // 0 (generators), 1 or 2 (diff, jwt)
Options []Option
Output OutputKind
Live bool // false = recompute only on F5 (expensive operations)
}
type Values ¶
Values holds the option values of a Request, keyed by Option.Key. The getters return the zero value when the key is missing or the type does not match.
func (Values) WithDefaults ¶
WithDefaults returns a copy of v filled in with spec's Default values for the missing keys.