Documentation ¶
Overview ¶
Package printer defines a set of CLI focused printers to show the results of an operation in different formats.
Index ¶
- Constants
- func PrintError(err error)
- func PrintResultOrError(printer ResultPrinter, result interface{}, err error) error
- type JSONPrinter
- type ResultPrinter
- type TablePrinter
- func (tp *TablePrinter) AddTemplate(templateType reflect.Type, templateContent string)
- func (tp *TablePrinter) AddTemplateFunction(name string, f interface{})
- func (tp *TablePrinter) CapitalizeWord(word string) string
- func (tp *TablePrinter) GetTemplate(result interface{}) (*string, error)
- func (tp *TablePrinter) Print(result interface{}) error
- func (tp *TablePrinter) PrintResultOrError(result interface{}, err error) error
Constants ¶
const ( // MinWidth is the minimal cell width including any padding. MinWidth = 8 // TabWidth is the width of tab characters (equivalent number of spaces) TabWidth = 4 // Padding added to a cell before computing its width Padding = 4 // PaddingChar with the ASCII char used for padding PaddingChar = ' ' // TabWriterFlags with the formatting options. TabWriterFlags = 0 )
Variables ¶
This section is empty.
Functions ¶
func PrintError ¶
func PrintError(err error)
func PrintResultOrError ¶
func PrintResultOrError(printer ResultPrinter, result interface{}, err error) error
PrintResultOrError prints the result using a given printer or the error.
Types ¶
type JSONPrinter ¶
type JSONPrinter struct { }
JSONPrinter structure with the implementation required to print as JSON a given result.
func (*JSONPrinter) Print ¶
func (jp *JSONPrinter) Print(result interface{}) error
Print the result.
func (*JSONPrinter) PrintResultOrError ¶
func (jp *JSONPrinter) PrintResultOrError(result interface{}, err error) error
PrintResultOrError prints the result using a given printer or the error.
type ResultPrinter ¶
type ResultPrinter interface { // Print the result. Print(result interface{}) error // PrintResultOrError prints the result using a given printer or the error. PrintResultOrError(result interface{}, err error) error }
ResultPrinter defines the operations that a printer must define. Multiple printer are offered depending on the desired output format.
func GetPrinter ¶
func GetPrinter(printerType string) (ResultPrinter, error)
GetPrinter creates a ResultPrinter attending to the user preferences.
func NewJSONPrinter ¶
func NewJSONPrinter() (ResultPrinter, error)
NewJSONPrinter build a new ResultPrinter whose output is the JSON representation of the object.
func NewTablePrinter ¶
func NewTablePrinter() (ResultPrinter, error)
NewTablePrinter builds a new ResultPrinter whose output is a human-readable table-like representation of the object.
type TablePrinter ¶
type TablePrinter struct {
// contains filtered or unexported fields
}
TablePrinter structure with the implementation required to print in a human-readable table format a given result.
func (*TablePrinter) AddTemplate ¶
func (tp *TablePrinter) AddTemplate(templateType reflect.Type, templateContent string)
func (*TablePrinter) AddTemplateFunction ¶
func (tp *TablePrinter) AddTemplateFunction(name string, f interface{})
AddTemplateFunction adds a new function so that it can be called in the golang template.
func (*TablePrinter) CapitalizeWord ¶
func (tp *TablePrinter) CapitalizeWord(word string) string
CapitalizeWord sets as upper case the first letters of a word
func (*TablePrinter) GetTemplate ¶
func (tp *TablePrinter) GetTemplate(result interface{}) (*string, error)
GetTemplate returns a template to print an arbitrary structure in table format.
func (*TablePrinter) Print ¶
func (tp *TablePrinter) Print(result interface{}) error
Print the result.
func (*TablePrinter) PrintResultOrError ¶
func (tp *TablePrinter) PrintResultOrError(result interface{}, err error) error
PrintResultOrError prints the result using a given printer or the error.