output

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package output renders command results either as aligned text tables (default) or as JSON (-o json) for scripting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format string

Format is the selected output format.

const (
	FormatTable Format = "table"
	FormatJSON  Format = "json"
)

func Parse

func Parse(s string) (Format, error)

Parse validates a --output value.

type Printer

type Printer struct {
	Format Format
	Out    io.Writer
}

Printer writes results in the chosen format.

func (Printer) JSON

func (p Printer) JSON(v any) error

JSON writes v as indented JSON. Used directly by read commands under -o json.

func (Printer) Render

func (p Printer) Render(v any, headers []string, rows [][]string) error

Render prints v as JSON when Format is JSON, otherwise calls table with the supplied header/row builder. This keeps every read command a one-liner.

func (Printer) Table

func (p Printer) Table(headers []string, rows [][]string) error

Table writes a header + rows as an aligned table.

Jump to

Keyboard shortcuts

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