pkg

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: MIT Imports: 14 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// JSONOutputFormat is the format of json
	JSONOutputFormat string = "json"
	// YAMLOutputFormat is the format of yaml
	YAMLOutputFormat string = "yaml"
	// TableOutputFormat is the format of table
	TableOutputFormat string = "table"
)
View Source
const (
	// AlignLeft align left
	AlignLeft = 0
	// AlignCenter align center
	AlignCenter = 1
	// AlignRight align right
	AlignRight = 2
)

Variables

View Source
var ShellTypes = []string{
	"zsh", "bash", "powerShell",
}

ShellTypes contains all types of shell

Functions

func Lenf

func Lenf(han string) (l int)

Lenf counts the number

func NewCompletionCmd

func NewCompletionCmd(rootCmd *cobra.Command) (cmd *cobra.Command)

NewCompletionCmd creates the completion command

func Pad

func Pad(s, pad string, width int, align int) string

Pad give a pad

func PadCenter

func PadCenter(s, pad string, width int) string

PadCenter pad as center

func PadLeft

func PadLeft(s, pad string, width int) string

PadLeft pad as left

func PadRight

func PadRight(s, pad string, width int) string

PadRight pas as right

func ReflectFieldValueAsString

func ReflectFieldValueAsString(v reflect.Value, field string) string

ReflectFieldValueAsString returns the value of a field

Types

type FormatOutput

type FormatOutput interface {
	Output(obj interface{}, format string) (data []byte, err error)
}

FormatOutput is the interface of format output

type OutputOption

type OutputOption struct {
	Format string

	Columns        string
	WithoutHeaders bool
	Filter         []string

	Writer        io.Writer
	CellRenderMap map[string]RenderCell
}

OutputOption represent the format of output

func (*OutputOption) GetLine

func (o *OutputOption) GetLine(obj reflect.Value) []string

GetLine returns the line of a table

func (*OutputOption) ListFilter

func (o *OutputOption) ListFilter(obj interface{}) interface{}

ListFilter filter the data list by fields

func (*OutputOption) Match

func (o *OutputOption) Match(item reflect.Value) bool

Match filter an item

func (*OutputOption) Output

func (o *OutputOption) Output(obj interface{}) (data []byte, err error)

Output print the object into byte array Deprecated see also OutputV2

func (*OutputOption) OutputV2

func (o *OutputOption) OutputV2(obj interface{}) (err error)

OutputV2 print the data line by line

func (*OutputOption) SetFlag

func (o *OutputOption) SetFlag(cmd *cobra.Command)

SetFlag set flag of output format Deprecated, see also SetFlagWithHeaders

func (*OutputOption) SetFlagWithHeaders

func (o *OutputOption) SetFlagWithHeaders(cmd *cobra.Command, headers string)

SetFlagWithHeaders set the flags of output

type RenderCell

type RenderCell = func(string) string

RenderCell render a specific cell in a table

type Table

type Table struct {
	Out          io.Writer
	Rows         [][]string
	ColumnWidths []int
	ColumnAlign  []int
	Separator    string

	WithHeader bool
}

Table for console print

func CreateTable

func CreateTable(out io.Writer) Table

CreateTable init a table object

func CreateTableWithHeader

func CreateTableWithHeader(out io.Writer, withoutHeader bool) (table Table)

CreateTableWithHeader init a table object

func (*Table) AddHeader

func (t *Table) AddHeader(col ...string)

AddHeader adds a header to the table

func (*Table) AddRow

func (t *Table) AddRow(col ...string)

AddRow adds a new row to the table

func (*Table) Clear

func (t *Table) Clear()

Clear removes all rows while preserving the layout

func (*Table) GetColumnAlign

func (t *Table) GetColumnAlign(i int) int

GetColumnAlign return the column alignment

func (*Table) Render

func (t *Table) Render()

Render render the table into byte array

func (*Table) SetColumnAlign

func (t *Table) SetColumnAlign(i int, align int)

SetColumnAlign sets the column alignment for the given column index

func (*Table) SetColumnsAligns

func (t *Table) SetColumnsAligns(colAligns []int)

SetColumnsAligns sets the alignment of the columns

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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