output

package
v1.26.4 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MPL-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package output renders API data as a table (default), JSON or YAML, with optional JMESPath --query, --no-header and quiet (ids only) modes. Colours honour NO_COLOR and are off when stdout is not a terminal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cell

func Cell(row any, c Column, color bool) string

Cell formats one cell.

func ColorEnabled

func ColorEnabled(w io.Writer, flagNoColor bool) bool

ColorEnabled decides colouring for a writer.

func Colorize

func Colorize(s string) string

Colorize paints well-known status words.

func Decode

func Decode(raw []byte) (any, error)

Decode turns raw JSON into generic Go values (float64 numbers, as JMESPath expects).

func IsMoney

func IsMoney(m map[string]any) bool

IsMoney reports {"amount": n, "currency": c}.

func Lookup

func Lookup(m map[string]any, path string) any

Lookup follows a dot path.

func Scalar

func Scalar(v any) string

Scalar renders a value for a table cell.

Types

type Column

type Column struct {
	Header string
	Path   string
	Format func(v any) string // optional
}

Column is one table column: Header is shown, Path is a dot path into each item (a.b.c).

func Derive

func Derive(rows []any, wide bool) []Column

Derive picks columns from list data: preferred keys first, then the rest alphabetically; nested objects other than money and arrays of objects are skipped. At most 8 columns unless wide.

func FromNames

func FromNames(names []string, max int) []Column

FromNames builds columns from spec property names.

type Printer

type Printer struct {
	W        io.Writer
	Format   string // table | json | yaml | text
	Query    string
	NoHeader bool
	Quiet    bool
	Color    bool
	Wide     bool
}

Printer holds the output options.

func (*Printer) Print

func (p *Printer) Print(data any, cols []Column, idPath string) error

Print renders data. cols may be nil (columns are then derived from the data). idPath is used by quiet mode ("id" by default). For lists wrapped in an object, pass the list itself.

Jump to

Keyboard shortcuts

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