output

package
v0.8.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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsStdoutTTY

func IsStdoutTTY() bool

IsStdoutTTY reports whether stdout is an interactive terminal. Respects NO_COLOR by returning false when set.

func Render

func Render(w io.Writer, v any, opts Opts) error

Render writes v to w in the format specified by opts.

func RenderToFile

func RenderToFile(path string, v any, opts Opts) error

RenderToFile writes v to the file at path. When opts.Format is empty or "auto", the format is inferred from the file extension (.json → "json"; anything else → "json" as default). Parent directories are created with mode 0755; the file is written with 0644.

func WriteRaw added in v0.2.0

func WriteRaw(path string, r io.Reader) error

WriteRaw streams r to the given file path (truncating). Intended for binary or extremely large payloads (e.g. workout SML/FIT exports) that should bypass the json/pretty formatter. This is the ONE sanctioned bypass of Render — every other command must go through Render/RenderToFile via emit().

func WriteRawStdout added in v0.2.0

func WriteRawStdout(r io.Reader) error

WriteRawStdout streams r to os.Stdout. Same caveat as WriteRaw.

Types

type Opts

type Opts struct {
	Format string // "json", "pretty", "auto", or ""
	IsTTY  bool
	// Fields, when non-empty, projects the encoded output down to just these
	// JSON keys before rendering. Forces JSON output (pretty rendering of an
	// arbitrary projection isn't well-defined). See projectJSON for shape rules.
	Fields []string
}

Opts controls how output is rendered.

type Prettier

type Prettier interface {
	Pretty() string
}

Prettier is implemented by values that know how to produce human-readable output.

type Tabular added in v0.5.0

type Tabular interface {
	Table() (headers []string, rows [][]string)
}

Tabular is implemented by list-shaped values that can produce a header row plus rows of cells. Used to render --format tsv (and reused by Pretty() for aligned text tables in endpoint code).

Jump to

Keyboard shortcuts

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