Documentation
¶
Overview ¶
Package output renders command results either as a styled table/summary for humans or as indented JSON for machines (--json).
Index ¶
- Variables
- func Emit(w io.Writer, asYAML bool, v any) error
- func Errorf(w io.Writer, format string, a ...any)
- func Hintf(w io.Writer, format string, a ...any)
- func HumanBlankLine(w io.Writer) error
- func Infof(w io.Writer, format string, a ...any)
- func JSON(w io.Writer, v any) error
- func KeyValues(w io.Writer, pairs [][2]string) error
- func PlainField(s string) string
- func Progressf(w io.Writer, format string, a ...any)
- func SanitizeField(s string) string
- func Successf(w io.Writer, format string, a ...any)
- func Table(w io.Writer, headers []string, rows [][]string) error
- func Title(w io.Writer, s string)
- func YAML(w io.Writer, v any) error
Constants ¶
This section is empty.
Variables ¶
var ( // Quiet suppresses incidental success/info lines (-q/--quiet). Quiet bool // Plain renders tables as tab-separated, unstyled rows (--plain). Plain bool // Interactive is true when stdout is a terminal. When false (piped or // redirected), Table drops its box-drawing frame so the rows stay // grep/awk-friendly, mirroring how color is stripped for non-TTY output. Interactive bool )
Output mode toggles set from global flags before commands run.
Functions ¶
func Emit ¶
Emit writes v as YAML when asYAML is set, otherwise as JSON. Commands that support --json also support the parallel --output yaml (or -o yaml) via this helper, so the two structured formats never need separate branches.
func Errorf ¶
Errorf prints an error line with a red dot. Unlike Successf/Infof it is never suppressed by Quiet — errors must always reach the user.
func Hintf ¶
Hintf writes a faint, indented follow-up line (e.g. a "try this next" hint after an error). Rendered on stderr by callers; not suppressed by --quiet so remediation guidance always shows.
func HumanBlankLine ¶
HumanBlankLine preserves a visual separator in human output without introducing an empty record in --plain output.
func Infof ¶
Infof prints a muted informational line with a primary-colored dot (suppressed in Quiet/Plain).
func JSON ¶
JSON writes v as indented JSON to w. A typed nil slice (e.g. `var x []T` with zero rows) marshals to `null`, which breaks scripts doing `… --json | jq '.[]'` or length checks on empty result sets, so it is coerced to an empty slice and serialized as [].
func PlainField ¶
PlainField makes one value safe to embed in a tab-separated, newline-delimited plain-output record without changing structured JSON or YAML data.
func Progressf ¶
Progressf prints transient progress only for an interactive human session, keeping redirected and machine-readable command output quiet.
func SanitizeField ¶
SanitizeField removes terminal control characters from untrusted values before they are embedded in human-readable output. Structured output must keep the original data, so callers apply this only at terminal render sites.
func Table ¶
Table renders a simple, aligned table with a styled header. Columns are sized to their widest cell. It is intentionally dependency-light so it can be used from any command. In Plain mode it emits tab-separated, unstyled rows for grep/awk pipelines.
Types ¶
This section is empty.