format

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package format is the tiny output abstraction used by ebctl commands. Each command builds a "row set" or a single value, hands it to a Printer, and the Printer decides whether to render a pretty table or JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Age

func Age(t time.Time) string

Age renders the time since t, suitable for table rows. Zero times become "—".

func HumanDuration

func HumanDuration(d time.Duration) string

HumanDuration is a compact rendering shared by table rows.

Types

type JSONPrinter

type JSONPrinter struct{}

JSONPrinter emits newline-delimited JSON blocks.

func (JSONPrinter) Name

func (JSONPrinter) Name() string

func (JSONPrinter) Table

func (JSONPrinter) Table(w io.Writer, headers []string, rows [][]string) error

func (JSONPrinter) Text

func (JSONPrinter) Text(w io.Writer, s string) error

func (JSONPrinter) Value

func (JSONPrinter) Value(w io.Writer, v any) error

type PrettyPrinter

type PrettyPrinter struct{}

PrettyPrinter renders tab-aligned tables and human text.

func (PrettyPrinter) Name

func (PrettyPrinter) Name() string

func (PrettyPrinter) Table

func (PrettyPrinter) Table(w io.Writer, headers []string, rows [][]string) error

func (PrettyPrinter) Text

func (PrettyPrinter) Text(w io.Writer, s string) error

func (PrettyPrinter) Value

func (PrettyPrinter) Value(w io.Writer, v any) error

type Printer

type Printer interface {
	// Table renders a headered table of rows. Ignored by JSON printer
	// (which uses Value instead).
	Table(w io.Writer, headers []string, rows [][]string) error
	// Value emits a single structured value. Pretty printer falls back to
	// fmt.Fprintf; JSON printer marshals.
	Value(w io.Writer, v any) error
	// Text emits a human-readable string. JSON printer wraps it as {"text": ...}.
	Text(w io.Writer, s string) error
	// Name returns the printer's canonical name ("pretty" or "json").
	Name() string
}

Printer is implemented by PrettyPrinter and JSONPrinter.

func New

func New(name string) (Printer, error)

New returns a Printer for the given format name. "pretty" and "" both yield the pretty printer.

Jump to

Keyboard shortcuts

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