output

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(format Format, data any) error

Print outputs data in the specified format. For JSON/YAML, data is serialized directly. For table, data must implement Tabular; if it does not, an error is returned.

func PrintTo added in v1.2.1

func PrintTo(w io.Writer, format Format, data any) error

PrintTo writes data to w in the specified format. Table output requires Tabular.

func ValidFormat added in v0.10.0

func ValidFormat(s string) bool

ValidFormat reports whether s is a recognized output format name.

func ValidFormats added in v0.10.0

func ValidFormats() []string

ValidFormats returns the list of recognized output format names.

Types

type Format

type Format string

Format represents an output format.

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

func ParseFormat

func ParseFormat(s string) Format

ParseFormat parses a format string, defaulting to table.

type NotTabularError added in v0.6.1

type NotTabularError struct {
	Got any
}

NotTabularError is returned by Print when table format is requested but the data does not implement Tabular. Use errors.As to inspect the type.

func (NotTabularError) Error added in v0.6.1

func (e NotTabularError) Error() string

type Tabular added in v0.6.1

type Tabular interface {
	Headers() []string
	Rows() [][]any
}

Tabular is implemented by result types that know how to render themselves as a table. Print uses this when the format is table; the same value is serialized directly for JSON/YAML.

Jump to

Keyboard shortcuts

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