Documentation
¶
Overview ¶
Package output renders categorized toolkit data to stdout in machine-friendly formats (json / jsonl / yaml / csv / tsv) or a human table.
It is intentionally TUI-free: it depends only on stdlib + yaml so the headless `toolkit get` command can be used in scripts and from LLM agents without paying the Bubble Tea cost.
Index ¶
- func Flatten[T any](grouped map[string][]T) []T
- func WriteDelimited(w io.Writer, headers []string, rows [][]string, opts Options, sep rune) error
- func WriteJSON(w io.Writer, items any, opts Options) error
- func WriteJSONL(w io.Writer, items any, _ Options) error
- func WriteTable(w io.Writer, headers []string, rows [][]string, opts Options) error
- func WriteYAML(w io.Writer, items any, _ Options) error
- type Format
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Flatten ¶ added in v0.4.0
Flatten concatenates a grouped map[string][]T into a flat []T with deterministic key ordering. Use when the group key is already preserved on each value (so injecting it again would just duplicate — see GPUNode.NodePool / ModelArtifact.ModelName). The returned slice preserves T's full type so the caller can keep using struct tags / custom JSON marshaling.
func WriteDelimited ¶
WriteDelimited emits headers + rows as delimiter-separated values using encoding/csv, which handles quoting for fields containing the separator, double quotes, or newlines. Pass ',' for CSV or '\t' for TSV. opts.NoHeaders suppresses the header row.
func WriteJSON ¶
WriteJSON emits items as a single JSON value (typically an array). A nil items value emits "[]" so pipelines like `| jq '.[]'` never see a null document.
func WriteJSONL ¶
WriteJSONL emits one JSON object per line. items must be a slice (each element becomes a line) or any single JSON-encodable value (emitted as one line).
Grouped/map data should be flattened with Flatten (the group key is expected to be a struct field on the value) before reaching this function.
func WriteTable ¶
WriteTable emits a tab-aligned table. opts.NoHeaders suppresses the header row even when headers is non-empty.
func WriteYAML ¶
WriteYAML emits items as a YAML document. Uses sigs.k8s.io/yaml, which marshals via JSON internally and therefore honors the same `json:` tags as WriteJSON — keeping -o json and -o yaml field names consistent without per-struct yaml tags. opts.Pretty has no effect (sigs.k8s.io/yaml has no indent knob; its default formatting is already human-readable).
Types ¶
type Format ¶
type Format string
Format is the on-the-wire encoding for `toolkit get`.
const ( FormatTable Format = "table" FormatJSON Format = "json" FormatJSONL Format = "jsonl" FormatYAML Format = "yaml" FormatCSV Format = "csv" FormatTSV Format = "tsv" )
Supported output formats for `toolkit get` and consumers that share the same encoding contract.
func ParseFormat ¶
ParseFormat returns the Format for s, or an error listing valid choices.