output

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 6 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 serialised directly. For table, data must implement Tabular; if it does not, an error is returned.

func ValidFormat added in v0.10.0

func ValidFormat(s string) bool

ValidFormat reports whether s is a recognised output format name.

func ValidFormats added in v0.10.0

func ValidFormats() []string

ValidFormats returns the list of recognised 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 serialised directly for JSON/YAML.

Jump to

Keyboard shortcuts

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