Help us shape the future of Go! Take the 2026 Go Developer Survey

output

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: CC0-1.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveMode

func ResolveMode(
	mode string,
	isTTY bool,
) string

ResolveMode maps the mode string to a concrete output format. When mode is "auto", it returns "text" for terminals and "json" for pipes.

Types

type Formatter

type Formatter struct {
	Mode string
	W    io.Writer
}

Formatter handles text and JSON output with auto-detection of terminal vs pipe.

func NewFormatter

func NewFormatter(
	mode string,
	w io.Writer,
) *Formatter

NewFormatter creates a Formatter that resolves "auto" mode by checking whether the writer is a terminal.

func (*Formatter) Error

func (f *Formatter) Error(
	err error,
)

Error writes an error message. Text: "error: msg\n". JSON: {"error": "msg"}.

func (*Formatter) Result

func (f *Formatter) Result(
	m map[string]any,
)

Result writes a map of key-value pairs. Text: sorted k/v lines. JSON: object.

func (*Formatter) Table

func (f *Formatter) Table(
	headers []string,
	rows [][]string,
)

Table writes tabular data. Text: aligned columns via tabwriter. JSON: array of objects keyed by headers.

func (*Formatter) Value

func (f *Formatter) Value(
	key string,
	val any,
)

Value writes a single key-value pair. Text: "key: val\n". JSON: {"key": val}.

func (*Formatter) WriteJSON

func (f *Formatter) WriteJSON(
	v any,
)

WriteJSON encodes v as JSON to the formatter's writer.

Jump to

Keyboard shortcuts

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