Documentation
¶
Index ¶
- Constants
- Variables
- func ConfigureOutputFormat(outFmt string) error
- func Default() string
- func ParseFormat(s string) (string, error)
- func Print(w io.Writer, outModel interface{}, format string) error
- func Render[T any](w io.Writer, format string, result T, renderRaw func(io.Writer, T) error) error
- func SetDefault(format string)
Constants ¶
const ( // FormatKey ... FormatKey = "format" // FormatRaw ... FormatRaw = "raw" // FormatJSON ... FormatJSON = "json" // FormatYML ... FormatYML = "yml" )
Variables ¶
var Format = FormatRaw
Format ...
Functions ¶
func ConfigureOutputFormat ¶
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 ¶
ParseFormat validates a format string without mutating any global state, accepting "human" as an alias for FormatRaw.
func Print ¶
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 ¶
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.