output

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package output formats API responses for the CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyQuery

func ApplyQuery(data interface{}, expr string) (interface{}, error)

ApplyQuery evaluates a JMESPath expression against data. Empty expr returns data unchanged.

func EncodeJSON

func EncodeJSON(data interface{}) ([]byte, error)

EncodeJSON returns indented JSON with HTML escaping disabled.

func Write

func Write(w io.Writer, format Format, data interface{}) error

Write formats data to w according to format, using default options.

func WriteWithOptions

func WriteWithOptions(w io.Writer, format Format, data interface{}, opts Options) error

WriteWithOptions formats data to w according to format and opts.

Types

type Format

type Format string

Format is a supported --output value.

const (
	FormatJSON     Format = "json"
	FormatTable    Format = "table"
	FormatTableNum Format = "table-num"
	FormatText     Format = "text"
	FormatYAML     Format = "yaml"
	FormatOff      Format = "off"
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat normalizes and validates an --output value. Empty string defaults to json.

type Options

type Options struct {
	// Columns is the preferred column order for table/text. It is applied only
	// when it exactly matches the keys present in the data; otherwise renderers
	// keep alphabetical order. See column_order.go.
	Columns []string

	// TerminalWidth caps table width. 0 means "detect from stdout"; a negative
	// value disables fitting entirely (useful for tests and for piped output
	// that should keep full-width columns).
	TerminalWidth int

	// Color enables ANSI styling for table headers and cells. Styling never
	// affects column widths; see style.go.
	Color bool
}

Options carries rendering hints that do not change the data itself.

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query is a validated JMESPath expression.

func CompileQuery

func CompileQuery(expr string) (*Query, error)

CompileQuery validates expr before an API request is sent. Empty expressions do not require a query.

func (*Query) Columns

func (q *Query) Columns() []string

Columns returns the column-order hint recovered from the expression. Nil means "no hint"; renderers then fall back to alphabetical order.

func (*Query) Search

func (q *Query) Search(data interface{}) (result interface{}, err error)

Search evaluates a previously validated query against the original response.

type QueryError

type QueryError struct {
	Expression string
	Offset     int // byte offset of the failure; -1 when unknown
	Err        error
}

QueryError explains why an expression failed to compile.

func (*QueryError) Error

func (e *QueryError) Error() string

func (*QueryError) Unwrap

func (e *QueryError) Unwrap() error

Jump to

Keyboard shortcuts

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