Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterOutputFlags ¶ added in v1.35.0
func WriteTemplate ¶ added in v1.35.0
WriteTemplate parses tmpl as a Go text/template (with the gh-compatible FuncMap) and executes it against v, writing the result to w.
Types ¶
type Field ¶
type Field[T any] struct { Name string Header string Extract func(T) any // Aliases are alternative names accepted by --json; they do not appear in // the valid-fields error list so the canonical name is always preferred. Aliases []string // JSONOnly marks a field that is available via --json but omitted from the // default table output (e.g. UUID, webURL columns that clutter the TTY view). JSONOnly bool // ColorFunc, if set, is applied to the rendered string in TTY table mode // only. It is intentionally NOT applied to JSON output, where consumers // expect raw values, nor in non-TTY table mode (piped output). ColorFunc func(string) string }
Field describes one output column and JSON key for type T.
type OutputConfig ¶ added in v1.35.0
type OutputConfig struct {
Format OutputFormat
JQExpr string
Template string
JSONFields []string // nil = all fields; non-nil = only these fields
}
OutputConfig captures the user-facing output-format selection — exactly one Format is active per invocation. JQExpr is only meaningful when Format == FormatJSON; Template only when Format == FormatTemplate. JSONFields, when non-nil, restricts JSON output to only the named fields; nil means all fields (backward compatible).
func ConfigFromCmd ¶ added in v1.35.0
func ConfigFromCmd(cmd *cobra.Command) OutputConfig
ConfigFromCmd reads the four output-format persistent flags from any cobra.Command. Works from any subcommand because Cobra merges persistent flags from ancestors. Falls back to FormatTable when the flags are not registered (e.g. a test calling a subcommand without a parent).
type OutputFormat ¶ added in v1.35.0
type OutputFormat string
OutputFormat enumerates supported output modes.
const ( // FormatTable is the default human-readable table output. FormatTable OutputFormat = "" // FormatJSON emits JSON, optionally piped through jq. FormatJSON OutputFormat = "json" // FormatYAML emits YAML. FormatYAML OutputFormat = "yaml" // FormatTemplate renders results through a Go text/template. FormatTemplate OutputFormat = "template" )
type Printer ¶
type Printer[T any] struct { // contains filtered or unexported fields }
Printer renders a slice of T in the correct output mode.
func (*Printer[T]) SetSingleItem ¶
func (p *Printer[T]) SetSingleItem()
SetSingleItem marks the printer to emit a single object (JSON/YAML/template) instead of an array.
func (*Printer[T]) ValidateJSONFields ¶ added in v1.86.0
ValidateJSONFields returns an error if any requested field is unknown. Only called when cfg.JSONFields is non-nil (i.e. --json field1,field2 was used).