Documentation
¶
Overview ¶
Package output provides formatters for CLI response rendering. A registry maps format names to Formatter implementations. The format is resolved at runtime from --output / env / config and selected via the registry.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Registry = map[string]Formatter{}
Registry maps format names to their Formatter implementation. Use Register in package init blocks or test setup to add new formats.
Functions ¶
func CompactBytes ¶
CompactBytes is a convenience that re-emits already-decoded data as compact JSON (no indentation).
func FormatJSONString ¶
func FormatJSONString(raw string, cfg FormatConfig) ([]byte, error)
FormatJSONString is a helper used when the raw response body has already been parsed once; it re-encodes the provided JSON string according to the format config.
Types ¶
type CSVFormatter ¶
type CSVFormatter struct{}
CSVFormatter renders arrays and objects as RFC 4180 CSV. Always writes a header row first, then one row per item.
func (*CSVFormatter) Format ¶
func (f *CSVFormatter) Format(data any, cfg FormatConfig) ([]byte, error)
func (*CSVFormatter) Name ¶
func (f *CSVFormatter) Name() string
type FormatConfig ¶
type FormatConfig struct {
Columns []string // restrict/reorder columns (table/csv)
Compact bool // force compact output (no indentation / colors)
Color bool // enable color output (TTY only by default)
}
FormatConfig controls formatting options shared by all formatters.
func (FormatConfig) Pretty ¶
func (cfg FormatConfig) Pretty() bool
Pretty returns true when the formatter should emit pretty JSON.
type Formatter ¶
type Formatter interface {
Name() string
Format(data any, cfg FormatConfig) ([]byte, error)
}
Formatter renders arbitrary data into bytes for stdout.
type JSONFormatter ¶
type JSONFormatter struct{}
JSONFormatter renders data as JSON. Pretty-prints with 2-space indentation when Color (TTY) is enabled and Compact is false; otherwise emits compact single-line JSON. When Color is true the pretty output is also syntax-highlighted using ANSI escape codes: keys in blue, strings in green, numbers in yellow, booleans in magenta, and null in red.
func (*JSONFormatter) Format ¶
func (f *JSONFormatter) Format(data any, cfg FormatConfig) ([]byte, error)
func (*JSONFormatter) Name ¶
func (f *JSONFormatter) Name() string
type RecordFormatter ¶ added in v0.2.0
type RecordFormatter struct{}
RecordFormatter renders data vertically — each record gets a header separator and its fields printed as aligned key: value pairs. Ideal for wide data, nested objects, or inspecting a single resource. Invoke with --output record.
func (*RecordFormatter) Format ¶ added in v0.2.0
func (f *RecordFormatter) Format(data any, cfg FormatConfig) ([]byte, error)
func (*RecordFormatter) Name ¶ added in v0.2.0
func (f *RecordFormatter) Name() string
type TableFormatter ¶
type TableFormatter struct{}
TableFormatter renders arrays and objects as ASCII tables using the charmbracelet/lipgloss/table package. Column inference:
- array of objects → first item's keys become columns,
- single object → its top-level keys become columns,
- empty array → "(empty)".
func (*TableFormatter) Format ¶
func (f *TableFormatter) Format(data any, cfg FormatConfig) ([]byte, error)
func (*TableFormatter) Name ¶
func (f *TableFormatter) Name() string
type YAMLFormatter ¶
type YAMLFormatter struct{}
YAMLFormatter renders data as YAML with 2-space indentation. No colorization is applied.
func (*YAMLFormatter) Format ¶
func (f *YAMLFormatter) Format(data any, cfg FormatConfig) ([]byte, error)
func (*YAMLFormatter) Name ¶
func (f *YAMLFormatter) Name() string