output

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Blue

func Blue(s string) string

func Bluef

func Bluef(s string, args ...interface{}) string

func Bold

func Bold(s string) string

func Boldf

func Boldf(s string, args ...interface{}) string

func Cyan

func Cyan(s string) string

func Cyanf

func Cyanf(s string, args ...interface{}) string

func Dim

func Dim(s string) string

func Dimf

func Dimf(s string, args ...interface{}) string

func Green

func Green(s string) string

func Greenf

func Greenf(s string, args ...interface{}) string

func Magenta

func Magenta(s string) string

func Magentaf

func Magentaf(s string, args ...interface{}) string

func PrintArray

func PrintArray[T any](items []T, cmd *cobra.Command, mappers Mappers[T]) error

func Red

func Red(s string) string

func Redf

func Redf(s string, args ...interface{}) string

func Truncate

func Truncate(maxWidth int, s string) string

func Yellow

func Yellow(s string) string

func Yellowf

func Yellowf(s string, args ...interface{}) string

Types

type IdAndName

type IdAndName struct {
	Id   string `json:"Id"`
	Name string `json:"Name"`
}

Common struct used for rendering JSON summaries of things that just have an ID and a Name

type Mappers

type Mappers[T any] struct {
	// A function which will convert T into an output structure suitable for json.Marshal (e.g. IdAndName).
	// If you leave this as nil, then the command will simply not support output as JSON and will
	// fail if someone asks for it
	Json func(item T) any

	// A function which will convert T into ?? suitable for table printing
	// If you leave this as nil, then the command will simply not support output as
	// a table and will fail if someone asks for it
	Table TableDefinition[T]

	// A function which will convert T into a string suitable for basic text display
	// If you leave this as nil, then the command will simply not support output as basic text and will
	// fail if someone asks for it
	Basic func(item T) string
}

carries conversion functions used by PrintArray and potentially other output code in future

type Table

type Table interface {
	AddRow(...string)
	Print() error
}

func NewTable

func NewTable(writer io.Writer) Table

type TableDefinition

type TableDefinition[T any] struct {
	Header []string
	Row    func(item T) []string
}

Jump to

Keyboard shortcuts

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