Documentation
¶
Overview ¶
Package output provides shared output formatting utilities for CLI commands. It supports four output modes:
- Default: Human-readable text output
- JSON: Pretty-printed JSON output
- Minimal: Token-optimized text output (no empty values, relative paths)
- Minimal+JSON: Single-line abbreviated JSON (minimal keys, no empty fields)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var KeyAbbreviations = map[string]string{
"file": "f",
"line": "l",
"name": "n",
"type": "t",
"question": "q",
"answer": "a",
"occurrences": "o",
"directories": "dirs",
"path": "p",
"message": "msg",
"status": "s",
"count": "c",
"total": "tot",
"value": "v",
"key": "k",
"result": "r",
"error": "err",
"success": "ok",
"files": "fs",
"matches": "m",
}
KeyAbbreviations maps full key names to abbreviated versions for minimal JSON output.
Functions ¶
func FilterEmpty ¶
FilterEmpty removes empty/zero values from a map.
func RelativePath ¶
RelativePath converts an absolute path to a path relative to the given base. If the path cannot be made relative, it returns the original path.
func RelativePathCwd ¶
RelativePathCwd converts an absolute path to a path relative to the current working directory.
Types ¶
type Formatter ¶
type Formatter struct {
JSON bool // Output as JSON
Minimal bool // Output in minimal/token-optimized mode
Writer io.Writer
}
Formatter handles output formatting with support for JSON and minimal modes.
func (*Formatter) Print ¶
Print outputs the data according to the formatter's configuration. For JSON mode, it marshals the data. For text mode, it uses the textFunc if provided. textFunc is called for default text output; if nil, JSON is used as fallback.
func (*Formatter) PrintLine ¶
PrintLine prints a key-value pair to the writer, respecting minimal mode.
func (*Formatter) PrintSection ¶
PrintSection prints a section header.