output

package
v3.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFormatType = fmt.Errorf("invalid format type")

ErrInvalidFormatType is returned when an unsupported format type is used

Functions

func EncodeJSON

func EncodeJSON(out io.Writer, obj interface{}) error

EncodeJSON is a helper function to decorate any error message with a bit more context and avoid writing the same code over and over for printers.

func EncodeTable

func EncodeTable(out io.Writer, table *uitable.Table) error

EncodeTable is a helper function to decorate any error message with a bit more context and avoid writing the same code over and over for printers

func EncodeYAML

func EncodeYAML(out io.Writer, obj interface{}) error

EncodeYAML is a helper function to decorate any error message with a bit more context and avoid writing the same code over and over for printers

func Formats

func Formats() []string

Formats returns a list of the string representation of the supported formats

func FormatsWithDesc

func FormatsWithDesc() map[string]string

FormatsWithDesc returns a list of the string representation of the supported formats including a description

Types

type Format

type Format string

Format is a type for capturing supported output formats

const (
	Table Format = "table"
	JSON  Format = "json"
	YAML  Format = "yaml"
)

func ParseFormat

func ParseFormat(s string) (out Format, err error)

ParseFormat takes a raw string and returns the matching Format. If the format does not exists, ErrInvalidFormatType is returned

func (Format) String

func (o Format) String() string

String returns the string representation of the Format

func (Format) Write

func (o Format) Write(out io.Writer, w Writer) error

Write the output in the given format to the io.Writer. Unsupported formats will return an error

type Writer

type Writer interface {
	// WriteTable will write tabular output into the given io.Writer, returning
	// an error if any occur
	WriteTable(out io.Writer) error
	// WriteJSON will write JSON formatted output into the given io.Writer,
	// returning an error if any occur
	WriteJSON(out io.Writer) error
	// WriteYAML will write YAML formatted output into the given io.Writer,
	// returning an error if any occur
	WriteYAML(out io.Writer) error
}

Writer is an interface that any type can implement to write supported formats

Jump to

Keyboard shortcuts

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