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",
"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. NOTE: "count" intentionally not abbreviated - other tools output "count" directly
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 ErrorResult ¶ added in v1.3.0
ErrorResult is a helper for creating error responses in handlers.
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) PrintError ¶ added in v1.3.0
PrintError outputs an error respecting JSON and Minimal modes. In JSON mode, outputs to stdout for parsing. In text mode, outputs to stderr. Returns the exit code (always 1 for errors).
func (*Formatter) PrintLine ¶
PrintLine prints a key-value pair to the writer, respecting minimal mode.
func (*Formatter) PrintSection ¶
PrintSection prints a section header.