output

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package output renders command results for either agents or humans. JSON is the default (machine-readable); table is human-friendly; ndjson streams one record per line for large result sets.

Index

Constants

View Source
const (
	FormatJSON   = "json"
	FormatTable  = "table"
	FormatNDJSON = "ndjson"
)

Format identifies an output format.

Variables

This section is empty.

Functions

func Emit

func Emit(v any, opt Options) error

Emit renders v to the configured writer in the configured format.

func EmitError

func EmitError(err error, w io.Writer)

EmitError writes a structured error as JSON to w (typically stderr). When the process was invoked with --pretty AND w is a TTY, the error JSON is also colorized; otherwise it falls back to plain JSON so log scrapers and non-TTY consumers see byte-identical output.

func EmitList

func EmitList(items any, next string, hasMore bool, opt Options) error

EmitList renders a paginated list result as a {items, next, has_more} envelope. Unlike Emit it is told explicitly that the value is a list, so the envelope shape never has to be guessed from the data. json emits the envelope; table renders the items as a grid with a cursor footer; ndjson streams the items, one per line.

func EmitNotice

func EmitNotice(w io.Writer, notice any)

EmitNotice writes a single compact JSON line carrying out-of-band notices (e.g. a newer-release notice, or input corrections) to w — typically stderr. It deliberately never touches stdout, so the command's data contract on stdout stays byte-identical; agents still see the notice via the shell. Failures are swallowed: a notice must never turn a successful command into a failure.

func SetErrorPretty

func SetErrorPretty(v bool)

SetErrorPretty toggles the process-global pretty flag for EmitError. It is called by the root command after parsing --pretty so error output styling matches success output styling.

Types

type Options

type Options struct {
	Format string
	// Fields, when non-empty, projects each record to these dot-path keys.
	Fields []string
	Writer io.Writer
	// Pretty enables ANSI-colored JSON when Writer is a TTY. It has no effect
	// on table output and is silently downgraded to plain JSON when Writer is
	// not a terminal (so e.g. `--pretty | jq` continues to work).
	Pretty bool
}

Options configures rendering.

Jump to

Keyboard shortcuts

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