output

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyJQFilter

func ApplyJQFilter(expr string, data any) (any, error)

ApplyJQFilter runs the given jq expression against data in-process (no external binary). If the expression produces exactly one result, it is returned directly. If it produces multiple results, they are returned as []any.

func NewTable

func NewTable(w io.Writer, isTTY bool) table.Writer

NewTable returns a go-pretty table.Writer configured to write to w. When isTTY is true, table.StyleLight is used (box-drawing characters). When false, table.StyleDefault is used (ASCII, suitable for piped output).

func WriteJSON

func WriteJSON(w io.Writer, data any) error

WriteJSON marshals data as indented JSON and writes it to w with a trailing newline.

func WriteJSONError

func WriteJSONError(w io.Writer, message string, code int) error

WriteJSONError writes {"error": message, "code": code} as indented JSON to w.

Types

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

Printer routes command output to JSON, jq-filtered JSON, or human table based on the global --json and --jq flags.

func NewPrinter

func NewPrinter(ios *iostreams.IOStreams, cmd *cobra.Command) *Printer

NewPrinter creates a Printer by reading --json and --jq flags from the cobra command. If --jq is set, JSON mode is implied.

func (*Printer) IsJSON

func (p *Printer) IsJSON() bool

IsJSON reports whether the printer is in JSON output mode.

func (*Printer) PrintData

func (p *Printer) PrintData(data any, populateFn func(table.Writer)) error

PrintData writes data to stdout. In JSON/jq mode it calls PrintJSON; otherwise it calls populateFn with a table.Writer. Pass nil for populateFn if only JSON output is needed.

func (*Printer) PrintDryRun

func (p *Printer) PrintDryRun(message string)

PrintDryRun writes a dry-run message to stdout. In JSON mode it writes {"dry_run": true, "message": "..."}. In table mode it writes "[dry-run] message\n".

func (*Printer) PrintError

func (p *Printer) PrintError(message string, code int) error

PrintError writes an error message to stderr. In JSON mode it writes {"error": "...", "code": N}. In table mode it writes plain text.

func (*Printer) PrintJSON

func (p *Printer) PrintJSON(data any) error

PrintJSON writes data as indented JSON to stdout. If a jq expression is configured, the filter is applied first.

func (*Printer) PrintTable

func (p *Printer) PrintTable(populateFn func(table.Writer))

PrintTable creates a go-pretty table, calls populateFn to add headers/rows, then renders.

Jump to

Keyboard shortcuts

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