output

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(w io.Writer, format Format, data any, columns []Column) error

Print writes data in the requested format to w. For table and CSV, data must be a slice; single objects can be wrapped in a one-element slice. If table or CSV is requested but no columns are defined (e.g. for free-form map[string]interface{} responses), Print falls back to JSON so the user sees something useful rather than a blank screen.

Types

type Column

type Column struct {
	Header string
	Field  string
}

Column describes one column of a table/CSV. Field is the Go struct field name (case-insensitive match).

type Format

type Format string

Format identifies an output format.

const (
	FormatTable Format = "table"
	FormatJSON  Format = "json"
	FormatYAML  Format = "yaml"
	FormatCSV   Format = "csv"
)

func DetectFormat

func DetectFormat(outputFlag string) Format

DetectFormat returns the format to use given the value of an --output flag. If the flag is non-empty it wins. Otherwise we pick `table` for TTYs and `json` for non-TTY output (pipes, files).

Jump to

Keyboard shortcuts

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