printers

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 17 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DescribeObject

func DescribeObject(v interface{}) error

DescribeObject writes a single object in the default format with default printer options retained for backwards compat with verb-noun commands which assume STDOUT

func ExitIfErr

func ExitIfErr(err error)

func FormatOutput

func FormatOutput(v interface{}, outputFormat string) (string, string, error)

FormatOutput writes a single object in the configured format

func StringInSlice

func StringInSlice(s []string, v string) bool

func StringPointer

func StringPointer(s string) *string

func WriteOutput

func WriteOutput(v interface{}, caption string, populateTable func(*tablewriter.Table)) error

WriteOutput writes output in the configured format with default printer options retained for backwards compat with verb-noun commands which assume STDOUT

Types

type IOStreams

type IOStreams struct {
	// In think, os.Stdin
	In io.Reader
	// Out think, os.Stdout
	Out io.Writer
	// ErrOut think, os.Stderr
	ErrOut io.Writer
}

IOStreams provides the standard names for iostreams. This is useful for embedding and for unit testing. Inconsistent and different names make it hard to read and review code

func DefaultOSStreams

func DefaultOSStreams() IOStreams

DefaultOSStreams returns a valid IOStreams pointing at os.Stdin, os.Stdout, os.Stderr

func NewTestIOStreams

func NewTestIOStreams() (IOStreams, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer)

NewTestIOStreams returns a valid IOStreams and in, out, errout buffers for unit tests

type PrinterOptions

type PrinterOptions struct {
	OutputFormat        string
	DefaultOutputFormat *string
	TableCaption        *string
	TablePopulateFN     *func(*tablewriter.Table)
	ItemsSelector       *func() interface{}
	IOStreams
}

PrinterOptions contains options for printing

func NewPrinterOptions

func NewPrinterOptions() *PrinterOptions

NewPrinterOptions defines new printer options

func (*PrinterOptions) ActiveOutputFormat added in v0.3.1

func (o *PrinterOptions) ActiveOutputFormat() string

ActiveOutputFormat provides the resolved output format (falling back to configured default, then text) this allows us to reduce the use of * which assumes that we have a value; this function always returns a string, resolving in one place the possibility of either configured o.OutputFormat or o.DefaultOutputFormat to be nil

func (*PrinterOptions) AddPrinterFlags

func (o *PrinterOptions) AddPrinterFlags(c *pflag.FlagSet)

AddPrinterFlags adds flags to a cobra.Command

func (*PrinterOptions) FWriteOutput added in v0.3.0

func (o *PrinterOptions) FWriteOutput(s io.Writer, v interface{}) error

FWriteOutput writes output to given ioWriter in the configured format

func (*PrinterOptions) FormatCategory

func (o *PrinterOptions) FormatCategory() string

FormatCategory returns the dereferenced format category

func (*PrinterOptions) FormatOutput

func (o *PrinterOptions) FormatOutput(v interface{}) (string, string, error)

FormatOutput writes a single object in the configured format

func (*PrinterOptions) ParseOutput

func (o *PrinterOptions) ParseOutput(in []byte, v interface{}) error

ParseOutput reads a single object in the configured format

func (*PrinterOptions) SupportedFormatCategories

func (o *PrinterOptions) SupportedFormatCategories() []string

SupportedFormatCategories returns the list of supported formats

func (*PrinterOptions) SupportedFormats

func (o *PrinterOptions) SupportedFormats() []string

SupportedFormats returns the list of supported formats

func (*PrinterOptions) Validate

func (o *PrinterOptions) Validate() error

Validate asserts that the printer options are valid

func (*PrinterOptions) WithDefaultOutput

func (o *PrinterOptions) WithDefaultOutput(output string) *PrinterOptions

WithDefaultOutput sets a default output format if one is not provided through a flag value

func (*PrinterOptions) WithDefaultTableWriter

func (o *PrinterOptions) WithDefaultTableWriter() *PrinterOptions

WithDefaultTableWriter sets a default table writer

func (*PrinterOptions) WithItemsSelector

func (o *PrinterOptions) WithItemsSelector(selectItems func() interface{}) *PrinterOptions

func (*PrinterOptions) WithStreams added in v0.2.0

func (o *PrinterOptions) WithStreams(s IOStreams) *PrinterOptions

WithStreams sets the IOStreams used by the PrinterOptions

func (*PrinterOptions) WithTableWriter

func (o *PrinterOptions) WithTableWriter(caption string, populateTable func(*tablewriter.Table)) *PrinterOptions

WithTableWriter decorates a PrinterOptions with table writer configuration

func (*PrinterOptions) WriteErr added in v0.3.0

func (o *PrinterOptions) WriteErr(v interface{}) error

WriteErr writes output to s.Err in the configured format

func (*PrinterOptions) WriteOutput

func (o *PrinterOptions) WriteOutput(v interface{}) error

WriteOutput writes output to s.Out in the configured format

type TestData added in v0.3.2

type TestData struct {
	IntField    int
	StringField string
}

type TestDataWithStringer added in v0.3.2

type TestDataWithStringer struct {
	TestData
}

func (TestDataWithStringer) String added in v0.3.2

func (d TestDataWithStringer) String() string

Jump to

Keyboard shortcuts

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