utils

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: MIT Imports: 18 Imported by: 0

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

func (IOStreams) WriteBytes

func (ios IOStreams) WriteBytes(b []byte) (int, error)

WriteBytes writes a byte array to o.Out

func (IOStreams) WriteBytesln

func (ios IOStreams) WriteBytesln(b []byte)

WriteBytesln writes a byte array to o.Out

func (IOStreams) WriteErrorBytes

func (ios IOStreams) WriteErrorBytes(b []byte) (int, error)

WriteErrorBytes writes a string to o.ErrOut

func (IOStreams) WriteErrorNewline

func (ios IOStreams) WriteErrorNewline() error

WriteErrorNewline writes a newline to o.ErrOut

func (IOStreams) WriteErrorString

func (ios IOStreams) WriteErrorString(s string) error

WriteErrorString writes a string to o.ErrOut

func (IOStreams) WriteNewline

func (ios IOStreams) WriteNewline() error

WriteNewline writes a newline to o.Out

func (IOStreams) WriteOutput

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

WriteOutput writes output to s.Out in the configured format

func (IOStreams) WriteString

func (ios IOStreams) WriteString(s string) error

WriteString writes a string to o.Out

func (IOStreams) WriteStringf

func (ios IOStreams) WriteStringf(format string, a ...interface{}) error

WriteStringf writes a string to o.Out

func (IOStreams) WriteStringln

func (ios IOStreams) WriteStringln(a ...interface{}) error

WriteStringln writes a string to o.Out with a newline

type PrinterOptions

type PrinterOptions struct {
	OutputFormat        *string
	DefaultOutputFormat *string
	Caption             *string
	PopulateTable       *func(*tablewriter.Table)
	ItemsSelector       *func() interface{}
}

PrinterOptions contains options for printing

func NewPrinterOptions

func NewPrinterOptions() *PrinterOptions

NewPrinterOptions defines new printer options

func (*PrinterOptions) AddPrinterFlags

func (o *PrinterOptions) AddPrinterFlags(c *cobra.Command)

AddPrinterFlags adds flags to a cobra.Command

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) WithTableWriter

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

WithTableWriter decorates a PrinterOptions with table writer configuration

func (*PrinterOptions) WriteOutput

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

WriteOutput writes output in the configured format

type ProjectedDateValue

type ProjectedDateValue struct {
	Date  *time.Time
	IsSet *bool
}

func NewProjectedDate

func NewProjectedDate() *ProjectedDateValue

NewProjectedDate creates a new instance of a ProjectedDateValue, allocating memory for both properties which can then be set using the Value pattern

func (ProjectedDateValue) Set

func (v ProjectedDateValue) Set(s string) error

Set implements pflag.Value

func (ProjectedDateValue) Type

func (v ProjectedDateValue) Type() string

Type implements pflag.Value

Jump to

Keyboard shortcuts

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