Documentation
¶
Overview ¶
Package cmdutil provides helper utilities and interfaces for working with command line tools
Index ¶
- Constants
- func Bg256(index int, s string) string
- func BgBlack(s string) string
- func BgBlue(s string) string
- func BgCyan(s string) string
- func BgGreen(s string) string
- func BgHiBlack(s string) string
- func BgHiBlue(s string) string
- func BgHiCyan(s string) string
- func BgHiGreen(s string) string
- func BgHiMagenta(s string) string
- func BgHiRed(s string) string
- func BgHiWhite(s string) string
- func BgHiYellow(s string) string
- func BgMagenta(s string) string
- func BgRed(s string) string
- func BgWhite(s string) string
- func BgYellow(s string) string
- func BlinkRapid(s string) string
- func BlinkSlow(s string) string
- func Bold(s string) string
- func Concealed(s string) string
- func ConvertKVStringsToMap(values []string) map[string]string
- func CrossedOut(s string) string
- func Faint(s string) string
- func Fg256(index int, s string) string
- func FgBlack(s string) string
- func FgBlue(s string) string
- func FgCyan(s string) string
- func FgGreen(s string) string
- func FgHiBlack(s string) string
- func FgHiBlue(s string) string
- func FgHiCyan(s string) string
- func FgHiGreen(s string) string
- func FgHiMagenta(s string) string
- func FgHiRed(s string) string
- func FgHiWhite(s string) string
- func FgHiYellow(s string) string
- func FgMagenta(s string) string
- func FgRed(s string) string
- func FgWhite(s string) string
- func FgYellow(s string) string
- func FormatDuration(d time.Duration) string
- func FormatPhase(phase string) string
- func Italic(s string) string
- func ParseVersion(in string) (string, error)
- func ReadKVStringsMapFromLabel(labels []string) map[string]string
- func Reset(s string) string
- func ReverseVideo(s string) string
- func SetColorLevel(level ColorLevel)
- func StyleBg256(index uint8) []color.Attribute
- func StyleFg256(index uint8) []color.Attribute
- func Underline(s string) string
- func Watch(ctx context.Context, id string, wf WatchFunc) error
- type App
- func (a *App) AddContainer(c *Container) *App
- func (a *App) Count() int
- func (a *App) Loop(ctx context.Context)
- func (a *App) Render() []byte
- func (a *App) SetMetadata(md map[string]any)
- func (a *App) UpdateMetadata(key string, value any)
- func (a *App) Wait()
- func (a *App) WaitAnd(fn func())
- func (a *App) WithLevel(l ColorLevel) *App
- type Codec
- type Color
- type Color16
- type Color256
- type ColorLevel
- type Column
- type Component
- type Container
- func (c *Container) Copies(n int) []*Container
- func (c *Container) Count() int
- func (c *Container) Render(data Data, frameIdx int) []byte
- func (c *Container) RenderLines(data Data, frameIdx int) []string
- func (c *Container) SetMetadata(data Data) *Container
- func (c *Container) UpdateMetadata(key string, value any)
- func (c *Container) WithLayout(l Layout) *Container
- func (c *Container) WithStyle(s Style) *Container
- type Dashboard
- func (d *Dashboard) AddTask(t *tasksv1.Task) int
- func (d *Dashboard) Done(idx int)
- func (d *Dashboard) DoneMsg(idx int, msg string)
- func (d *Dashboard) Fail(idx int)
- func (d *Dashboard) FailAfter(idx int, after time.Duration)
- func (d *Dashboard) FailAfterMsg(idx int, after time.Duration, msg string)
- func (d *Dashboard) FailMsg(idx int, msg string)
- func (d *Dashboard) IsDone() bool
- func (d *Dashboard) Loop(ctx context.Context)
- func (d *Dashboard) SetTask(idx int, t *tasksv1.Task)
- func (d *Dashboard) Update(idx int, fn func(s *ServiceState))
- func (d *Dashboard) Wait()
- func (d *Dashboard) WaitAnd(fn func())
- type Data
- type Deserializer
- type Detail
- type Element
- type Field
- type JSONCodec
- type JSONDeserializer
- type JSONSerializer
- type Layout
- type Option
- type OutputFormat
- type Renderer
- type Serializer
- type ServiceState
- type StopFunc
- type Style
- type SyncWriter
- type TableSerializer
- type WatchFunc
- type YamlCodec
- type YamlDeserializer
- type YamlSerializer
Constants ¶
const ( Color16FgBlack color.Attribute = iota + 30 Color16FgRed Color16FgGreen Color16FgYellow Color16FgBlue Color16FgMagenta Color16FgCyan Color16FgWhite )
Foreground text colors
const ( Color16FgHiBlack color.Attribute = iota + 90 Color16FgHiRed Color16FgHiGreen Color16FgHiYellow Color16FgHiBlue Color16FgHiMagenta Color16FgHiCyan Color16FgHiWhite )
Foreground Hi-Intensity text colors
const ( Color16BgBlack color.Attribute = iota + 40 Color16BgRed Color16BgGreen Color16BgYellow Color16BgBlue Color16BgMagenta Color16BgCyan Color16BgWhite )
Background text colors
const ( Color16BgHiBlack color.Attribute = iota + 100 Color16BgHiRed Color16BgHiGreen Color16BgHiYellow Color16BgHiBlue Color16BgHiMagenta Color16BgHiCyan Color16BgHiWhite )
Background Hi-Intensity text colors
const ( AttrReset color.Attribute = iota AttrBold AttrFaint AttrItalic AttrUnderline AttrBlinkSlow AttrBlinkRapid AttrReverseVideo AttrConcealed AttrCrossedOut AttrResetBold color.Attribute = iota + 22 AttrResetItalic AttrResetUnderline AttrResetBlinking AttrResetReversed AttrResetConcealed AttrResetCrossedOut )
Attributes
Variables ¶
This section is empty.
Functions ¶
func Bg256 ¶ added in v0.0.16
Bg256 applies a 256-color palette background color index should be 0-255
func BgHiMagenta ¶ added in v0.0.16
func BgHiYellow ¶ added in v0.0.16
func BlinkRapid ¶ added in v0.0.16
func ConvertKVStringsToMap ¶ added in v0.0.13
ConvertKVStringsToMap converts a slice of "key=value" strings into a map.
func CrossedOut ¶ added in v0.0.16
func Fg256 ¶ added in v0.0.16
Fg256 applies a 256-color palette foreground color index should be 0-255
func FgHiMagenta ¶ added in v0.0.16
func FgHiYellow ¶ added in v0.0.16
func FormatDuration ¶
func FormatPhase ¶
func ParseVersion ¶
ParseVersion parses the provided string and ensures that it is a valid. Allowed values are either semver (prefixed with v), "latest" and "head". Case is ignored. If the version is valid, this function will resolv the version to a GitHub release name to ensure that the release exists.
func ReadKVStringsMapFromLabel ¶ added in v0.0.13
ReadKVStringsMapFromLabel convers string slice into map
func ReverseVideo ¶ added in v0.0.16
func SetColorLevel ¶ added in v0.0.16
func SetColorLevel(level ColorLevel)
SetColorLevel sets the global color level for auto-downgrade support
func StyleBg256 ¶ added in v0.0.16
StyleBg256 helper for 256-color backgrounds
func StyleFg256 ¶ added in v0.0.16
StyleFg256 helper for 256-color foregrounds
Types ¶
type App ¶ added in v0.0.16
App is the top most item and renders child containers.
func NewApp ¶ added in v0.0.16
NewApp creates a new App using the given writer and containers and children.
func (*App) AddContainer ¶ added in v0.0.16
func (*App) Count ¶ added in v0.0.16
Count returns the total amount of lines all child containers render.
func (*App) SetMetadata ¶ added in v0.0.16
SetMetadata updates metadata for template access
func (*App) UpdateMetadata ¶ added in v0.0.16
UpdateMetadata sets metadata key for template access
func (*App) WaitAnd ¶ added in v0.0.16
func (a *App) WaitAnd(fn func())
WaitAnd blocks until Loop finishes and then calls fn.
func (*App) WithLevel ¶ added in v0.0.16
func (a *App) WithLevel(l ColorLevel) *App
type Codec ¶
type Codec interface {
Serializer
Deserializer
}
func NewJSONCodec ¶
func NewJSONCodec() Codec
func NewYamlCodec ¶
func NewYamlCodec() Codec
type ColorLevel ¶ added in v0.0.16
type ColorLevel int
const ( LevelNone ColorLevel = iota Level16 Level256 )
type Column ¶ added in v0.0.16
type Column struct {
Template string // Raw template string for this column
Width int // Max width (0 = unlimited)
Parsed *template.Template // Compiled template (set during initialization)
}
Column defines a single column in the dashboard output
type Component ¶ added in v0.0.16
type Component interface {
// Loop runs the rendering loop until context is cancelled
Loop(context.Context)
// Wait blocks until the renderer is done
Wait()
// Close cleans up resources
Close() error
}
Component describes how objects are rendered frame by frame
type Container ¶ added in v0.0.16
Container renders elements on the screen. Contaner holds layout information such as dimensions and padding.
func NewContainer ¶ added in v0.0.16
NewContainer creates a new 1x1 container with the given elements and children. func NewContainer(style Style, opts Layout, r ...*Element) *Container {
func (*Container) Count ¶ added in v0.0.16
Count returns the total amount of lines all child elements render.
func (*Container) RenderLines ¶ added in v0.0.16
func (*Container) SetMetadata ¶ added in v0.0.16
SetMetadata updates metadata for template access
func (*Container) UpdateMetadata ¶ added in v0.0.16
UpdateMetadata sets metadata key for template access
func (*Container) WithLayout ¶ added in v0.0.16
type Dashboard ¶
type Dashboard struct {
Name string
// contains filtered or unexported fields
}
Dashboard holds all services + rendering logic
func NewDashboard ¶
NewDashboard creates the dashboard with one ServiceState per name.
func (*Dashboard) AddTask ¶ added in v0.0.16
AddTask adds a new task dynamically to dashboard (returns index)
func (*Dashboard) FailAfterMsg ¶
FailAfterMsg sets the provided message marks the service as faild when x amount of time as elapsed
func (*Dashboard) Loop ¶
Loop calls loop on the underlying App instance passing the context through to it
func (*Dashboard) SetTask ¶ added in v0.0.16
SetTask overwrites existing task at idx a new instance dynamically
func (*Dashboard) Update ¶
func (d *Dashboard) Update(idx int, fn func(s *ServiceState))
Update lets workers mutate a single service under lock.
type Deserializer ¶
func DeserializerFor ¶
func DeserializerFor(s string) (Deserializer, error)
type Detail ¶ added in v0.0.11
Detail represents a line in the details view of a ServiceState. It's pretty much just a key-value pair
type Element ¶ added in v0.0.16
type Element struct {
Template string // Raw template string for this column
Width int // Max width (0 = unlimited)
Parsed *template.Template // Compiled template (set during initialization)
}
func NewElement ¶ added in v0.0.16
NewElement creates a new element with the provided format string.
type Field ¶ added in v0.0.18
type Field int
Field identifies a detail line that can be shown per task entry in the dashboard.
type JSONCodec ¶
type JSONCodec struct {
*JSONSerializer
*JSONDeserializer
}
type JSONDeserializer ¶
type JSONDeserializer struct{}
func (*JSONDeserializer) Deserialize ¶
func (d *JSONDeserializer) Deserialize(b []byte, m proto.Message) error
type JSONSerializer ¶
type JSONSerializer struct{}
type Option ¶ added in v0.0.11
type Option func(*Dashboard)
func WithEmptyText ¶ added in v0.0.16
WithEmptyText sets the text to display when the list of services is empty
func WithFields ¶ added in v0.0.18
WithFields sets which detail fields are displayed beneath each task entry. Fields are rendered in the order they appear in defaultFields regardless of the order they are passed here. If WithFields is not called, all fields are shown (equivalent to passing all Field constants).
func WithFlushFunc ¶ added in v0.0.11
func WithFlushFunc(f func()) Option
WithFlushFunc adds a handler to the dashboard that is executed on each render loop. This is useful when for writers that require flushing. Such as the build-in tabwriter pkg writer.
func WithHeader ¶ added in v0.0.16
WithHeader sets a header line that will be rendered once at the start
func WithWriter ¶
WithWriter assigns a io.Writer that the Dashboard will render to. The default writer is os.Stdout. If the writer literal types can be cast to a tabwriter.Writer its Flush() methods will be assigned as the loopFunc. see WithLoopFunc for more info. Basically it is set here so the user doesn't have to bother.
type OutputFormat ¶
type OutputFormat string
var ( OutputFormatJSON OutputFormat = "json" OutputFormatYAML OutputFormat = "yaml" OutputFormatTable OutputFormat = "table" )
type Serializer ¶
func SerializerFor ¶
func SerializerFor(s string) (Serializer, error)
type ServiceState ¶
type ServiceState struct {
Done bool
DoneMsg string
Failed bool
FailedMsg string
// contains filtered or unexported fields
}
ServiceState represents One line in the dashboard
type SyncWriter ¶
type SyncWriter struct {
// contains filtered or unexported fields
}
type TableSerializer ¶
type TableSerializer struct{}
type YamlCodec ¶
type YamlCodec struct {
*YamlSerializer
*YamlDeserializer
}
type YamlDeserializer ¶
type YamlDeserializer struct{}
func (*YamlDeserializer) Deserialize ¶
func (d *YamlDeserializer) Deserialize(b []byte, m proto.Message) error
type YamlSerializer ¶
type YamlSerializer struct{}