output

package
v0.0.1-testing Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 13 Imported by: 1 module, 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 command results either for humans (tables, relative times, colors) or for programs (json, yaml, ndjson, jq), from the same data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RelativeTime

func RelativeTime(d time.Duration) string

RelativeTime renders a duration since an event in a human-friendly way.

Types

type Cell

type Cell struct {
	Text  string
	Style func(string) string
}

Cell is a table cell with an optional style applied only on a TTY.

type Format

type Format string
const (
	FormatTable  Format = "table"
	FormatPlain  Format = "plain"
	FormatJSON   Format = "json"
	FormatYAML   Format = "yaml"
	FormatNDJSON Format = "ndjson"
)

type Options

type Options struct {
	JSON   string
	JQ     string
	Output string
}

Options are the output-related global flags.

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

type Printer

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

Printer writes command results to stdout in the resolved format.

func NewPrinter

func NewPrinter(io *iostreams.IOStreams, o Options, defaultFormat string) (*Printer, error)

NewPrinter resolves the output format from flags, the default setting and the terminal.

func (*Printer) Format

func (p *Printer) Format() Format

func (*Printer) IsHuman

func (p *Printer) IsHuman() bool

IsHuman reports whether output is the decorated TTY table format.

func (*Printer) IsMachine

func (p *Printer) IsMachine() bool

IsMachine reports whether output is structured data (json/yaml/ndjson).

func (*Printer) Print

func (p *Printer) Print(data any, human func() error) error

Print writes data in a machine format, or calls human() for table/plain output. data should be JSON-serializable and use stable lower_snake/camel keys.

func (*Printer) ShortID

func (p *Printer) ShortID(id string) string

ShortID abbreviates long IDs on a TTY ("01hq…a1"); full IDs otherwise.

func (*Printer) Table

func (p *Printer) Table(headers ...string) *Table

func (*Printer) Time

func (p *Printer) Time(t time.Time) string

Time formats a timestamp: relative on a TTY ("2 hours ago"), RFC3339 otherwise.

type Table

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

Table renders rows as an aligned, borderless table on a TTY and as tab-separated values without a header otherwise.

func (*Table) Len

func (t *Table) Len() int

func (*Table) Render

func (t *Table) Render() error

func (*Table) Row

func (t *Table) Row(values ...any)

Row adds a row. Each value may be a string, a Cell, or anything fmt can print.

Jump to

Keyboard shortcuts

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