Documentation
¶
Overview ¶
Package output renders API objects as tables, JSON or YAML.
Index ¶
- Variables
- func Age(v any) string
- func Decode(raw json.RawMessage) map[string]any
- func Duration(v any) string
- func Get(obj map[string]any, path string) any
- func HumanDuration(d time.Duration) string
- func KV(w io.Writer, pairs [][2]string)
- func Safe(s string) string
- func SortBy(items []json.RawMessage, c Column)
- func Text(v any) string
- func ValidFormat(f string) bool
- func WriteYAML(w io.Writer, raw []byte) error
- type Column
- type Printer
Constants ¶
This section is empty.
Variables ¶
var Formats = []string{"table", "wide", "json", "yaml", "name"}
Formats accepted by -o.
Functions ¶
func Decode ¶
func Decode(raw json.RawMessage) map[string]any
Decode turns a raw JSON object into a generic map (numbers kept exact).
func HumanDuration ¶
HumanDuration formats d like kubectl ages: 45s, 12m, 5h3m, 3d4h, 2y.
func Safe ¶
Safe makes a value safe to print on a terminal: control characters (C0, DEL, C1, which include ESC and CSI), line and paragraph separators and bidirectional overrides are shown as \xNN / \uNNNN escapes, and a tab becomes a space so it cannot break table alignment. Use it for every value that came from the API in human-readable output; JSON and YAML have their own escaping and keep the data as is.
func SortBy ¶
func SortBy(items []json.RawMessage, c Column)
SortBy sorts items by the display value of a column (case-insensitive).
func Text ¶
Text renders scalars and short lists. Trailing NUL bytes, which some clients report at the end of their hostname, are dropped.
func ValidFormat ¶
ValidFormat reports whether f is a known output format.
Types ¶
type Column ¶
type Column struct {
Header string
// Paths are dotted JSON paths tried in order; the first non-empty wins.
Paths []string
// Format converts the raw value to display text. Defaults to Text.
Format func(v any) string
// Wide columns only appear with -o wide.
Wide bool
}
Column describes one table column.
type Printer ¶
type Printer struct {
Format string
NoHeaders bool
// NameFunc returns the identifier printed by -o name.
NameFunc func(obj map[string]any) string
}
Printer writes objects in the selected format.
func (Printer) PrintObject ¶
PrintObject prints a single raw JSON document (json or yaml; table/wide fall back to yaml, which is the most readable form for nested objects).