output

package
v2.8.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutputOptionRequired = errors.New("output option required")

Functions

func NA

func NA(s string) string

func ParseOutputOptions

func ParseOutputOptions(out string) (string, []string)

func YesNo

func YesNo(b bool) string

Types

type FieldFn

type FieldFn func(obj any) string

type Table

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

Table is a generic way to format object as a table.

func NewTable

func NewTable(out io.Writer) *Table

NewTable creates a new Table.

func (*Table) AddAllowedFields

func (o *Table) AddAllowedFields(obj any) (*Table, error)

AddAllowedFields reads all first level field names of the struct and allows them to be used.

func (*Table) AddFieldAlias

func (o *Table) AddFieldAlias(field, alias string) *Table

AddFieldAlias overrides the field name to allow custom column headers.

func (*Table) AddFieldFn

func (o *Table) AddFieldFn(field string, fn FieldFn) *Table

AddFieldFn adds a function which handles the output of the specified field.

func (*Table) Columns

func (o *Table) Columns() (cols []string)

Columns returns a list of known output columns.

func (*Table) Flush

func (o *Table) Flush() error

func (*Table) RemoveAllowedField

func (o *Table) RemoveAllowedField(fields ...string) *Table

RemoveAllowedField removes fields from the allowed list.

func (*Table) ValidateColumns

func (o *Table) ValidateColumns(cols []string) error

ValidateColumns returns an error if invalid columns are specified.

func (*Table) Write

func (o *Table) Write(columns []string, obj any) error

Write writes a table line.

func (*Table) WriteHeader

func (o *Table) WriteHeader(columns []string)

WriteHeader writes the table header.

Jump to

Keyboard shortcuts

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