format

package
v1.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field[T any] struct {
	Name    string
	Header  string
	Extract func(T) any
	// Aliases are alternative names accepted by --json; they do not appear in
	// the valid-fields error list so the canonical name is always preferred.
	Aliases []string
	// JSONOnly marks a field that is available via --json but omitted from the
	// default table output (e.g. UUID, webURL columns that clutter the TTY view).
	JSONOnly bool
	// ColorFunc, if set, is applied to the rendered string in TTY table mode
	// only. It is intentionally NOT applied to JSON output, where consumers
	// expect raw values, nor in non-TTY table mode (piped output).
	ColorFunc func(string) string
}

Field describes one output column and JSON key for type T.

type Printer

type Printer[T any] struct {
	// contains filtered or unexported fields
}

Printer renders a slice of T in the correct output mode.

func New

func New[T any](w io.Writer, isTTY bool, jsonFields, jqExpr string) *Printer[T]

New constructs a Printer.

func (*Printer[T]) AddField

func (p *Printer[T]) AddField(f Field[T])

AddField registers a field.

func (*Printer[T]) AddItem

func (p *Printer[T]) AddItem(item T)

AddItem enqueues one result item.

func (*Printer[T]) Render

func (p *Printer[T]) Render() error

Render writes all items in the appropriate format.

func (*Printer[T]) SetSingleItem

func (p *Printer[T]) SetSingleItem()

SetSingleItem marks the printer to emit a JSON object instead of an array.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL