output

package
v3.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FormatKey ...
	FormatKey = "format"
	// FormatRaw ...
	FormatRaw = "raw"
	// FormatJSON ...
	FormatJSON = "json"
	// FormatYML ...
	FormatYML = "yml"
)

Variables

View Source
var Format = FormatRaw

Format ...

Functions

func ConfigureOutputFormat

func ConfigureOutputFormat(outFmt string) error

ConfigureOutputFormat sets the global Format from a command's --format flag value, falling back to the resolved default (see SetDefault) when empty.

func Default

func Default() string

Default returns the format set by SetDefault. Commands that render through their own logger instead of ConfigureOutputFormat need it to honour the root-persistent --output flag.

func ParseFormat

func ParseFormat(s string) (string, error)

ParseFormat validates a format string without mutating any global state, accepting "human" as an alias for FormatRaw.

func Print

func Print(w io.Writer, outModel interface{}, format string) error

Print marshals outModel per format and writes it to w, indented. Returns an error instead of logging it, so a marshaling failure surfaces as a non-zero exit rather than a silently successful command.

func Render

func Render[T any](w io.Writer, format string, result T, renderRaw func(io.Writer, T) error) error

Render writes result via renderRaw for FormatRaw, or via Print otherwise — the "raw table/text vs. json/yml" branch every command needs, in one place.

func SetDefault

func SetDefault(format string)

SetDefault sets the format ConfigureOutputFormat falls back to when a command's own --format flag is unset. This is what lets a root-persistent --output flag (or the "output" config key) take effect without touching any per-command --format call site.

Types

This section is empty.

Jump to

Keyboard shortcuts

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