formatter

package
v0.0.0-...-63c62f7 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableFormatKey  = "table"
	RawFormatKey    = "raw"
	PrettyFormatKey = "pretty"
	JSONFormatKey   = "json"

	DefaultQuietFormat = "{{.ID}}"

	ListCommandKey = "list"

	// default header use accross multiple formatter
	// UniverseHeader
	UniversesHeader = "Universes"
	// DescriptionHeader
	DescriptionHeader = "Description"
	// NameHeader
	NameHeader = "Name"
	// RegionsHeader
	RegionsHeader = "Regions"
	// StateHeader
	StateHeader = "State"
	// ProviderHeader
	ProviderHeader = "Provider"
	// StorageConfigurationHeader
	StorageConfigurationHeader = "Storage Configuration"
	// CodeHeader
	CodeHeader = "Code"
	// UUIDHeader
	UUIDHeader = "UUID"
	// StatusHeader
	StatusHeader = "Status"
	// InUseHeader
	InUseHeader = "In Use"
	// KMSConfigHeader
	KMSConfigHeader = "KMS configuration"
	// CreateTimeHeader to display create time
	CreateTimeHeader = "Create Time"
	// UpdateTimeHeader to display update time
	UpdateTimeHeader = "Update Time"
	// TypeHeader to display type
	TypeHeader = "Type"

	// GreenColor for colored output
	GreenColor = "green"
	// RedColor for colored output
	RedColor = "red"
	// BlueColor for colored output
	BlueColor = "blue"
	// YellowColor for colored output
	YellowColor = "yellow"
)

Format keys used to specify certain kinds of output formats

Variables

This section is empty.

Functions

func Colorize

func Colorize(message string, colors string) string

Colorize the message accoring the colors var

func Truncate

func Truncate(text string, lenght int) string

Truncate the text according to the length

Types

type Command

type Command string

Command represets the type of command being executed

func (Command) IsListCommand

func (c Command) IsListCommand() bool

IsListCommand returns true if the command is a list command

type Context

type Context struct {
	// Output is the output stream to which the formatted string is written.
	Output io.Writer
	// Format is used to choose raw, table or custom format for the output.
	Format Format

	// Command is the command being executed
	Command Command

	// ContextHeader to avoid ambiguity between HeaderContext.Header and Context.Header
	ContextHeader interface{}
	// Buffer
	Buffer *bytes.Buffer
	// contains filtered or unexported fields
}

Context contains information required by the formatter to print the output as desired.

func (*Context) ContextFormat

func (c *Context) ContextFormat(tmpl *template.Template, subContext SubContext) error

ContextFormat function

func (*Context) ParseFormat

func (c *Context) ParseFormat() (*template.Template, error)

ParseFormat function

func (*Context) PostFormat

func (c *Context) PostFormat(tmpl *template.Template, subContext SubContext)

PostFormat function

func (*Context) PreFormat

func (c *Context) PreFormat()

PreFormat function

func (*Context) Write

func (c *Context) Write(sub SubContext, f SubFormat) error

Write the template to the Buffer using this Context

type Format

type Format string

Format is the format string rendered using the Context

func (Format) Contains

func (f Format) Contains(sub string) bool

Contains returns true if the format contains the substring

func (Format) IsJSON

func (f Format) IsJSON() bool

IsJSON returns true if the format is the json format

func (Format) IsPrettyJSON

func (f Format) IsPrettyJSON() bool

IsPrettyJSON returns true if the format is the json format

func (Format) IsTable

func (f Format) IsTable() bool

IsTable returns true if the format is a table-type format

type HeaderContext

type HeaderContext struct {
	Header interface{}
}

HeaderContext provides the subContext interface for managing headers

func (*HeaderContext) FullHeader

func (c *HeaderContext) FullHeader() interface{}

FullHeader returns the header as an interface

type SubContext

type SubContext interface {
	FullHeader() interface{}
}

SubContext defines what Context implementation should provide

type SubFormat

type SubFormat func(func(SubContext) error) error

SubFormat is a function type accepted by Write()

type SubHeaderContext

type SubHeaderContext map[string]string

SubHeaderContext is a map destined to formatter header (table format)

func (SubHeaderContext) Label

func (c SubHeaderContext) Label(name string) string

Label returns the header label for the specified string

Jump to

Keyboard shortcuts

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