Documentation ¶
Index ¶
- func IsShowable(value any) bool
- type FieldRenderOptions
- type FieldValue
- type FieldValueOption
- type JsonPrinter
- type Listable
- type PrintableResource
- type Printer
- type RenderFunc
- type ResourcePrinter
- type RowData
- type ShowPrinter
- type Showable
- type StringPrinter
- type Table
- type TablePrinter
- type TableRow
- type YamlPrinter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsShowable ¶
Types ¶
type FieldRenderOptions ¶
type FieldRenderOptions struct {
// contains filtered or unexported fields
}
type FieldValue ¶
func NewFieldValue ¶
func NewFieldValue(name string, value any, opts ...FieldValueOption) FieldValue
func (FieldValue) ValueString ¶
func (f FieldValue) ValueString() string
type FieldValueOption ¶
type FieldValueOption func(*FieldValue)
func WithListKey ¶
func WithListKey() FieldValueOption
WithListKey sets this field as the key when the item is rendered as a list
func WithListKeyRender ¶
func WithListKeyRender(render RenderFunc) FieldValueOption
WithListKeyRender sets this field as the key when the item is rendered as a list and provides a function to render the key
func WithRenderValueFunc ¶
func WithRenderValueFunc(render RenderFunc) FieldValueOption
type JsonPrinter ¶
func NewJsonPrinter ¶
func NewJsonPrinter[T any]() (*JsonPrinter[T], error)
func (JsonPrinter[T]) PrintResource ¶
func (p JsonPrinter[T]) PrintResource(ctx context.Context, r PrintableResource[T], writer io.Writer) error
type Listable ¶
type Listable interface {
GetListData() *RowData
}
Listable is an interface implemented by objects which support the `list` command for pretty/plain output format
type PrintableResource ¶
type RenderFunc ¶
type RenderFunc func(opts sanitize.RenderOptions) string
type ResourcePrinter ¶
type ResourcePrinter[T any] interface { // PrintResource receives a runtime object, formats it and prints it to a writer. PrintResource(context.Context, PrintableResource[T], io.Writer) error }
ResourcePrinter is an interface that knows how to print runtime objects.
func GetPrinter ¶
func GetPrinter[T any](cmd *cobra.Command) (ResourcePrinter[T], error)
type RowData ¶
type RowData struct { // slice of column names (converted to lower case) Columns []string // map of fields keyed by lower case column name Fields map[string]FieldValue // contains filtered or unexported fields }
RowData is a struct that holds the data for a single row of a table
func NewRowData ¶
func NewRowData(fields ...FieldValue) *RowData
func (*RowData) AddField ¶
func (d *RowData) AddField(f FieldValue)
func (*RowData) GetDisplayColumns ¶
type ShowPrinter ¶
type ShowPrinter[T any] struct{}
func NewShowPrinter ¶
func NewShowPrinter[T any]() (*ShowPrinter[T], error)
func (ShowPrinter[T]) PrintResource ¶
func (p ShowPrinter[T]) PrintResource(_ context.Context, r PrintableResource[T], writer io.Writer) error
type Showable ¶
type Showable interface {
GetShowData() *RowData
}
Showable is an interface implemented by objects which support the `show` command for pretty/plain output format
func AsShowable ¶
type StringPrinter ¶
type StringPrinter[T any] struct { Sanitizer *sanitize.Sanitizer // contains filtered or unexported fields }
func NewStringPrinter ¶
func NewStringPrinter[T any]() (*StringPrinter[T], error)
func (StringPrinter[T]) PrintResource ¶
func (p StringPrinter[T]) PrintResource(_ context.Context, r PrintableResource[T], writer io.Writer) error
type Table ¶
type Table struct { Rows []TableRow Columns []string FieldOpts map[string]FieldRenderOptions }
func (*Table) WithRow ¶
func (t *Table) WithRow(fields ...FieldValue) *Table
type TablePrinter ¶
TablePrinter decodes table objects into typed objects before delegating to another printer. Non-table types are simply passed through
func NewTablePrinter ¶
func NewTablePrinter[T any]() (*TablePrinter[T], error)
func (TablePrinter[T]) PrintResource ¶
func (p TablePrinter[T]) PrintResource(_ context.Context, items PrintableResource[T], writer io.Writer) error
func (TablePrinter[T]) PrintTable ¶
func (p TablePrinter[T]) PrintTable(table *Table, writer io.Writer) error
type TableRow ¶
type TableRow struct { Columns []string Cells []any // map of field name to field render options Opts map[string]FieldRenderOptions }
func NewTableRow ¶
func NewTableRow(fields ...FieldValue) *TableRow
type YamlPrinter ¶
Inspired by https://github.com/goccy/go-yaml/blob/master/cmd/ycat/ycat.go
func NewYamlPrinter ¶
func NewYamlPrinter[T any]() (*YamlPrinter[T], error)
func (YamlPrinter[T]) PrintResource ¶
func (px YamlPrinter[T]) PrintResource(ctx context.Context, r PrintableResource[T], writer io.Writer) error