Documentation
¶
Overview ¶
Package output renders API responses in one of four formats: json (default), yaml, jsonl, table — optionally narrowed by --columns (dotted-path projection). Heavier transformations belong on the right of a `| jq` pipe — we deliberately don't ship a half-jq. Epoch-millis date fields (anything with format=date-time-millis in the spec) are humanised to ISO-8601 across every format so jq pipelines and humans see the same readable timestamp.
Index ¶
- func ColorizeJSON(b []byte) []byte
- func HumanizeDates(v interface{}) interface{}
- func Plain(v interface{}) interface{}
- func Print(v interface{}) error
- func PrintJSON(v interface{}) error
- func Project(v interface{}, cols []string) interface{}
- func SanitizeForTerminal(s string) string
- func SetCellMax(n int)
- func SetColumns(c string)
- func SetDateKeys(keys map[string]bool)
- func SetFormat(f string)
- func UseColor(w io.Writer) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColorizeJSON ¶
ColorizeJSON wraps a pre-formatted JSON byte slice in the same ANSI color scheme `--output json` uses (cyan keys, green strings, yellow numbers, magenta bool/null). Pass through unchanged input that isn't a tty target.
func HumanizeDates ¶
func HumanizeDates(v interface{}) interface{}
HumanizeDates is the exported entry point for the same transformation Print applies — used by hand-written commands (e.g. `bron tx subscribe`) that build their own output pipelines but still want ISO dates by default.
func Plain ¶
func Plain(v interface{}) interface{}
Plain converts the order-preserving orderedMap nodes that Project produces back into plain map[string]interface{} throughout v, leaving every other value (and number type) untouched. Consumers that expect standard JSON container types — gojq in particular — panic on the orderedMap wrapper; run the value through Plain first. Returns a new tree.
func Print ¶
func Print(v interface{}) error
Print renders v according to the global format/columns.
func PrintJSON ¶
func PrintJSON(v interface{}) error
PrintJSON is kept as an alias for callers that want JSON regardless of globals.
func Project ¶
func Project(v interface{}, cols []string) interface{}
Project narrows v to the given dot-paths, returning a new tree (the input is not mutated). Empty cols returns v unchanged.
Arrays are traversed transparently: a path segment that lands on an array is applied to every element, so `events.type` keeps `type` from each object in the `events` array, and the outer list envelope ({"transactions":[...]}) needs no prefix. Paths sharing a prefix merge under it — `_embedded.price` plus `_embedded.baseAssetId` yields one `_embedded` object carrying both. There is no brace-group syntax; list each leaf path.
This is the same projection `--columns` applies to json/yaml output, exposed as a pure function so the MCP server can shape tool responses per call without touching the package-global `columns` (its handlers run concurrently).
func SanitizeForTerminal ¶
SanitizeForTerminal strips C0/C1 control bytes from a server-controlled string before it lands in a human-readable terminal context (table cells, stderr error fields). Without it, an attacker with workspace-write access could embed `\x1b]0;evil\x07` (title hijack) or `\r` (overwrite earlier columns) in account names / memos. JSON/YAML structured encoders escape control chars natively, so this is only needed on the raw-print path.
Keeps `\t` (column separator) and `\n` (line break in long strings).
func SetCellMax ¶
func SetCellMax(n int)
SetCellMax sets the per-cell character cap for table output. 0 disables truncation entirely (useful on wide terminals where full IDs / addresses matter more than alignment). Negative or unset values keep the default.
func SetColumns ¶
func SetColumns(c string)
SetColumns selects which fields to render in --output table. Comma-separated list (e.g. "transactionId,status,createdAt"). Empty disables filtering.
func SetDateKeys ¶
SetDateKeys configures the set of property names whose values are epoch-milliseconds — populated at CLI startup from the OpenAPI spec by collecting leaves with `format: "date-time-millis"`. Output formatters humanize values for these keys to ISO-8601 UTC. Empty set disables humanization entirely.
func SetFormat ¶
func SetFormat(f string)
SetFormat updates the global output format. Empty string is ignored.
func UseColor ¶
UseColor reports whether ANSI colors should be used when writing to w. Honors NO_COLOR (disable, any value) and FORCE_COLOR (enable, any value), otherwise enables colors only for ttys. Exposed so other packages can match the CLI's rendering rules without rewriting the detection logic.
Types ¶
This section is empty.