printer

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const NoneString = "<none>"

Variables

View Source
var (
	// KubeCtlStyle renders a Table like kubectl
	KubeCtlStyle table.Style

	// TerminalStyle renders a Table like below:
	//  +-----+------------+-----------+--------+-----------------------------+
	//  |   # | FIRST NAME | LAST NAME | SALARY |                             |
	//  +-----+------------+-----------+--------+-----------------------------+
	//  |   1 | Arya       | Stark     |   3000 |                             |
	//  |  20 | Jon        | Snow      |   2000 | You know nothing, Jon Snow! |
	//  | 300 | Tyrion     | Lannister |   5000 |                             |
	//  +-----+------------+-----------+--------+-----------------------------+
	//  |     |            | TOTAL     |  10000 |                             |
	//  +-----+------------+-----------+--------+-----------------------------+
	TerminalStyle = table.Style{
		Name:    "TerminalStyle",
		Box:     table.StyleBoxDefault,
		Color:   table.ColorOptionsDefault,
		Format:  table.FormatOptionsDefault,
		HTML:    table.DefaultHTMLOptions,
		Options: table.OptionsDefault,
		Title:   table.TitleOptionsDefault,
	}
)
View Source
var ErrInvalidFormatType = fmt.Errorf("invalid format type")

Functions

func AddOutputFlag

func AddOutputFlag(cmd *cobra.Command, varRef *Format)

func AddOutputFlagForCreate

func AddOutputFlagForCreate(cmd *cobra.Command, varRef *Format, persistent bool)

func Alert

func Alert(out io.Writer, format string, i ...interface{})

func BoldGreen

func BoldGreen(msg interface{}) string

BoldGreen returns a string formatted with green and bold.

func BoldRed

func BoldRed(msg interface{}) string

BoldRed returns a string formatted with red and bold.

func BoldYellow

func BoldYellow(msg interface{}) string

BoldYellow returns a string formatted with yellow and bold.

func FatalWithRedColor

func FatalWithRedColor(msg string, code int)

FatalWithRedColor when an error occurs, sets the red color to print it.

func Formats

func Formats() []string

func FormatsWithDesc

func FormatsWithDesc() map[string]string

func PrettyPrintObj

func PrettyPrintObj(obj *unstructured.Unstructured) error

func PrintAllWarningEvents

func PrintAllWarningEvents(events *corev1.EventList, out io.Writer)

func PrintBlankLine

func PrintBlankLine(out io.Writer)

PrintBlankLine prints a blank line

func PrintComponentConfigMeta

func PrintComponentConfigMeta(tplInfos []types.ConfigTemplateInfo, clusterName, componentName string, out io.Writer)

PrintComponentConfigMeta prints the conditions of resource.

func PrintConditions

func PrintConditions(conditions []metav1.Condition, out io.Writer)

PrintConditions prints the conditions of resource.

func PrintHelmValues

func PrintHelmValues(configs map[string]interface{}, format Format, out io.Writer)

PrintHelmValues prints the helm values file of the release in specified format, supports JSON、YAML and Table

func PrintLine

func PrintLine(line string)

func PrintLineWithTabSeparator

func PrintLineWithTabSeparator(ps ...Pair)

func PrintPairStringToLine

func PrintPairStringToLine(name, value string, spaceCount ...int)

PrintPairStringToLine prints pair string for a line , the format is as follows "<space>*<key>:\t<value>". spaceCount is the space character count which is placed in the offset of field string. the default values of tabCount is 2.

func PrintTable

func PrintTable(out io.Writer, customSettings func(*TablePrinter), rowFeeder func(*TablePrinter) error, header ...interface{}) error

PrintTable high level wrapper function.

func PrintTitle

func PrintTitle(title string)

func Warning

func Warning(out io.Writer, format string, i ...interface{})

Types

type Format

type Format string

Format is a type for capturing supported output formats

const (
	Table Format = "table"
	JSON  Format = "json"
	YAML  Format = "yaml"
	Wide  Format = "wide"
)

func ParseFormat

func ParseFormat(s string) (out Format, err error)

func (Format) IsHumanReadable

func (f Format) IsHumanReadable() bool

func (Format) String

func (f Format) String() string

type Pair

type Pair string

func NewPair

func NewPair(key, value string) Pair

type TablePrinter

type TablePrinter struct {
	Tbl table.Writer
}

func NewTablePrinter

func NewTablePrinter(out io.Writer) *TablePrinter

func (*TablePrinter) AddRow

func (t *TablePrinter) AddRow(row ...interface{})

func (*TablePrinter) Print

func (t *TablePrinter) Print()

func (*TablePrinter) SetHeader

func (t *TablePrinter) SetHeader(header ...interface{})

func (*TablePrinter) SetStyle

func (t *TablePrinter) SetStyle(style table.Style)

func (*TablePrinter) SortBy

func (t *TablePrinter) SortBy(columnNumber ...int)

SortBy sorts the table alphabetically by the column you specify, it will be sorted by the first table column in default. The columnNumber index starts from 1

Jump to

Keyboard shortcuts

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