Documentation
¶
Overview ¶
Package render defines output formats for bage command results and the helpers to parse them from user-facing flags.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Emit ¶
Emit writes v to w in the given Format. FormatJSON marshals indented JSON, FormatText delegates to v's RenderText method (v must implement TextRenderable), and FormatTOON marshals a TOON document via MarshalTOON. An unknown Format is reported as a usage error.
func MarshalTOON ¶
MarshalTOON encodes v as a TOON (token-oriented object notation) document. Slices of flat structs render as tabular arrays with a single header row naming each field once, using the comma array delimiter. Struct fields opt into named output via the `toon:"..."` struct tag.
Types ¶
type Format ¶
type Format string
Format identifies how a command renders its output. Its zero value is not a valid format; use ParseFormat to obtain a Format from a flag value, which resolves the empty string to the default FormatText.
const ( // FormatText renders human-readable plain text. It is the default format // when the --format flag is empty. FormatText Format = "text" // FormatJSON renders machine-readable JSON. FormatJSON Format = "json" // FormatTOON renders TOON (token-oriented object notation) output. FormatTOON Format = "toon" )
func ParseFormat ¶
ParseFormat maps the --format flag to a Format. An EMPTY string resolves to FormatText, the default. A non-empty value must match a known format's canonical name ("text", "json", or "toon"); anything else is an explicit usage error rather than a silent fallthrough.
type Renderer ¶
type Renderer interface {
// Render writes v to w in the renderer's format.
Render(w io.Writer, v any) error
}
Renderer writes a command result value to w in a single output format. Implementations are selected by Format and are safe to use as zero values.
type TextRenderable ¶
type TextRenderable interface {
// RenderText writes the receiver's human-readable representation to w.
RenderText(w io.Writer) error
}
TextRenderable is implemented by result types that know how to render themselves as human-readable text. The text renderer type-asserts values to this interface, so a domain type opts in simply by defining RenderText — without importing pkg/render and thus without an import cycle.