cmdutil

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package cmdutil provides helper utilities and interfaces for working with command line tools

Index

Constants

View Source
const (
	Color16FgBlack color.Attribute = iota + 30
	Color16FgRed
	Color16FgGreen
	Color16FgYellow
	Color16FgBlue
	Color16FgMagenta
	Color16FgCyan
	Color16FgWhite
)

Foreground text colors

View Source
const (
	Color16FgHiBlack color.Attribute = iota + 90
	Color16FgHiRed
	Color16FgHiGreen
	Color16FgHiYellow
	Color16FgHiBlue
	Color16FgHiMagenta
	Color16FgHiCyan
	Color16FgHiWhite
)

Foreground Hi-Intensity text colors

View Source
const (
	Color16BgBlack color.Attribute = iota + 40
	Color16BgRed
	Color16BgGreen
	Color16BgYellow
	Color16BgBlue
	Color16BgMagenta
	Color16BgCyan
	Color16BgWhite
)

Background text colors

View Source
const (
	Color16BgHiBlack color.Attribute = iota + 100
	Color16BgHiRed
	Color16BgHiGreen
	Color16BgHiYellow
	Color16BgHiBlue
	Color16BgHiMagenta
	Color16BgHiCyan
	Color16BgHiWhite
)

Background Hi-Intensity text colors

View Source
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

func Bg256(index int, s string) string

Bg256 applies a 256-color palette background color index should be 0-255

func BgBlack added in v0.0.16

func BgBlack(s string) string

func BgBlue added in v0.0.16

func BgBlue(s string) string

func BgCyan added in v0.0.16

func BgCyan(s string) string

func BgGreen added in v0.0.16

func BgGreen(s string) string

func BgHiBlack added in v0.0.16

func BgHiBlack(s string) string

func BgHiBlue added in v0.0.16

func BgHiBlue(s string) string

func BgHiCyan added in v0.0.16

func BgHiCyan(s string) string

func BgHiGreen added in v0.0.16

func BgHiGreen(s string) string

func BgHiMagenta added in v0.0.16

func BgHiMagenta(s string) string

func BgHiRed added in v0.0.16

func BgHiRed(s string) string

func BgHiWhite added in v0.0.16

func BgHiWhite(s string) string

func BgHiYellow added in v0.0.16

func BgHiYellow(s string) string

func BgMagenta added in v0.0.16

func BgMagenta(s string) string

func BgRed added in v0.0.16

func BgRed(s string) string

func BgWhite added in v0.0.16

func BgWhite(s string) string

func BgYellow added in v0.0.16

func BgYellow(s string) string

func BlinkRapid added in v0.0.16

func BlinkRapid(s string) string

func BlinkSlow added in v0.0.16

func BlinkSlow(s string) string

func Bold added in v0.0.16

func Bold(s string) string

func Concealed added in v0.0.16

func Concealed(s string) string

func ConvertKVStringsToMap added in v0.0.13

func ConvertKVStringsToMap(values []string) map[string]string

ConvertKVStringsToMap converts a slice of "key=value" strings into a map.

func CrossedOut added in v0.0.16

func CrossedOut(s string) string

func Faint added in v0.0.16

func Faint(s string) string

func Fg256 added in v0.0.16

func Fg256(index int, s string) string

Fg256 applies a 256-color palette foreground color index should be 0-255

func FgBlack added in v0.0.16

func FgBlack(s string) string

func FgBlue added in v0.0.16

func FgBlue(s string) string

func FgCyan added in v0.0.11

func FgCyan(s string) string

func FgGreen added in v0.0.11

func FgGreen(s string) string

func FgHiBlack added in v0.0.16

func FgHiBlack(s string) string

func FgHiBlue added in v0.0.16

func FgHiBlue(s string) string

func FgHiCyan added in v0.0.16

func FgHiCyan(s string) string

func FgHiGreen added in v0.0.16

func FgHiGreen(s string) string

func FgHiMagenta added in v0.0.16

func FgHiMagenta(s string) string

func FgHiRed added in v0.0.16

func FgHiRed(s string) string

func FgHiWhite added in v0.0.16

func FgHiWhite(s string) string

func FgHiYellow added in v0.0.16

func FgHiYellow(s string) string

func FgMagenta added in v0.0.16

func FgMagenta(s string) string

func FgRed added in v0.0.11

func FgRed(s string) string

func FgWhite added in v0.0.16

func FgWhite(s string) string

func FgYellow added in v0.0.11

func FgYellow(s string) string

func FormatDuration

func FormatDuration(d time.Duration) string

func FormatPhase

func FormatPhase(phase string) string

func Italic added in v0.0.16

func Italic(s string) string

func ParseVersion

func ParseVersion(in string) (string, error)

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

func ReadKVStringsMapFromLabel(labels []string) map[string]string

ReadKVStringsMapFromLabel convers string slice into map

func Reset added in v0.0.16

func Reset(s string) string

func ReverseVideo added in v0.0.16

func ReverseVideo(s string) string

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

func StyleBg256(index uint8) []color.Attribute

StyleBg256 helper for 256-color backgrounds

func StyleFg256 added in v0.0.16

func StyleFg256(index uint8) []color.Attribute

StyleFg256 helper for 256-color foregrounds

func Underline added in v0.0.16

func Underline(s string) string

func Watch

func Watch(ctx context.Context, id string, wf WatchFunc) error

Types

type App added in v0.0.16

type App struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

App is the top most item and renders child containers.

func NewApp added in v0.0.16

func NewApp(wr io.Writer, data Data, containers ...*Container) *App

NewApp creates a new App using the given writer and containers and children.

func (*App) AddContainer added in v0.0.16

func (a *App) AddContainer(c *Container) *App

func (*App) Count added in v0.0.16

func (a *App) Count() int

Count returns the total amount of lines all child containers render.

func (*App) Loop added in v0.0.16

func (a *App) Loop(ctx context.Context)

Loop renders the app each frame

func (*App) Render added in v0.0.16

func (a *App) Render() []byte

Render implements Renderer

func (*App) SetMetadata added in v0.0.16

func (a *App) SetMetadata(md map[string]any)

SetMetadata updates metadata for template access

func (*App) UpdateMetadata added in v0.0.16

func (a *App) UpdateMetadata(key string, value any)

UpdateMetadata sets metadata key for template access

func (*App) Wait added in v0.0.16

func (a *App) Wait()

Wait blocks until Loop finishes.

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 CodecFor

func CodecFor(s string) (Codec, error)

func NewJSONCodec

func NewJSONCodec() Codec

func NewYamlCodec

func NewYamlCodec() Codec

type Color

type Color string

type Color16 added in v0.0.16

type Color16 uint8 // ANSI 16-color (0-15)

type Color256 added in v0.0.16

type Color256 uint8 // ANSI 256-color palette (0-255)

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

type Container struct {
	Layout
	Style
	ContentWidth int
	// contains filtered or unexported fields
}

Container renders elements on the screen. Contaner holds layout information such as dimensions and padding.

func NewContainer added in v0.0.16

func NewContainer(data Data, r ...*Element) *Container

NewContainer creates a new 1x1 container with the given elements and children. func NewContainer(style Style, opts Layout, r ...*Element) *Container {

func (*Container) Copies added in v0.0.16

func (c *Container) Copies(n int) []*Container

func (*Container) Count added in v0.0.16

func (c *Container) Count() int

Count returns the total amount of lines all child elements render.

func (*Container) Render added in v0.0.16

func (c *Container) Render(data Data, frameIdx int) []byte

Render implements Renderer

func (*Container) RenderLines added in v0.0.16

func (c *Container) RenderLines(data Data, frameIdx int) []string

func (*Container) SetMetadata added in v0.0.16

func (c *Container) SetMetadata(data Data) *Container

SetMetadata updates metadata for template access

func (*Container) UpdateMetadata added in v0.0.16

func (c *Container) UpdateMetadata(key string, value any)

UpdateMetadata sets metadata key for template access

func (*Container) WithLayout added in v0.0.16

func (c *Container) WithLayout(l Layout) *Container

func (*Container) WithStyle added in v0.0.16

func (c *Container) WithStyle(s Style) *Container

type Dashboard

type Dashboard struct {
	Name string
	// contains filtered or unexported fields
}

Dashboard holds all services + rendering logic

func NewDashboard

func NewDashboard(names []string, opts ...Option) (*Dashboard, error)

NewDashboard creates the dashboard with one ServiceState per name.

func (*Dashboard) AddTask added in v0.0.16

func (d *Dashboard) AddTask(t *tasksv1.Task) int

AddTask adds a new task dynamically to dashboard (returns index)

func (*Dashboard) Done

func (d *Dashboard) Done(idx int)

Done marks the service entry at idx as done

func (*Dashboard) DoneMsg

func (d *Dashboard) DoneMsg(idx int, msg string)

DoneMsg sets the provided message when the Dashboard is done

func (*Dashboard) Fail

func (d *Dashboard) Fail(idx int)

Fail marks the service as failed

func (*Dashboard) FailAfter

func (d *Dashboard) FailAfter(idx int, after time.Duration)

FailAfter marks the service as faild when x amount of time as elapsed

func (*Dashboard) FailAfterMsg

func (d *Dashboard) FailAfterMsg(idx int, after time.Duration, msg string)

FailAfterMsg sets the provided message marks the service as faild when x amount of time as elapsed

func (*Dashboard) FailMsg

func (d *Dashboard) FailMsg(idx int, msg string)

FailMsg sets the provided message and marks the service as failed

func (*Dashboard) IsDone

func (d *Dashboard) IsDone() bool

IsDone return true if all services in the Dashboard is marked as done

func (*Dashboard) Loop

func (d *Dashboard) Loop(ctx context.Context)

Loop calls loop on the underlying App instance passing the context through to it

func (*Dashboard) SetTask added in v0.0.16

func (d *Dashboard) SetTask(idx int, t *tasksv1.Task)

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.

func (*Dashboard) Wait

func (d *Dashboard) Wait()

Wait blocks until Loop finishes.

func (*Dashboard) WaitAnd

func (d *Dashboard) WaitAnd(fn func())

WaitAnd blocks until Loop finishes and executes the provided function when done

type Data added in v0.0.16

type Data map[string]any

Data holds information used when templating

type Deserializer

type Deserializer interface {
	Deserialize(b []byte, m proto.Message) error
}

func DeserializerFor

func DeserializerFor(s string) (Deserializer, error)

type Detail added in v0.0.11

type Detail struct {
	Key   string
	Value string
}

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

func NewElement(format string) *Element

NewElement creates a new element with the provided format string.

func (*Element) Count added in v0.0.16

func (e *Element) Count() int

Count returns the total amount of lines all child elements render. Always returns 1 since elements never span across multiple lines.

func (*Element) Render added in v0.0.16

func (e *Element) Render(d any, frameIdx int) []byte

Render implements Renderer. frameIdx is the current animation frame owned by the App; it is passed in rather than read from a shared variable to avoid data races.

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.

const (
	FieldPhase Field = iota
	FieldNode
	FieldPid
	FieldID
	FieldImage
)

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{}

func (*JSONSerializer) Serialize

func (s *JSONSerializer) Serialize(m proto.Message) ([]byte, error)

type Layout added in v0.0.16

type Layout struct {
	Dimensions [2]int // Width, Height
	Padding    [4]int // Top, right, bottom, left
}

type Option added in v0.0.11

type Option func(*Dashboard)

func WithEmptyText added in v0.0.16

func WithEmptyText(text string) Option

WithEmptyText sets the text to display when the list of services is empty

func WithFields added in v0.0.18

func WithFields(fields ...Field) Option

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

func WithHeader(header string) Option

WithHeader sets a header line that will be rendered once at the start

func WithWriter

func WithWriter(w io.Writer) Option

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 Renderer added in v0.0.16

type Renderer interface {
	Render(any) []byte
}

Renderer describes how objects are renderd on to the screen

type Serializer

type Serializer interface {
	Serialize(m proto.Message) ([]byte, error)
}

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 StopFunc

type StopFunc func()

type Style added in v0.0.16

type Style struct {
	Bg   []color.Attribute
	Fg   []color.Attribute
	Attr color.Attribute
}

type SyncWriter

type SyncWriter struct {
	// contains filtered or unexported fields
}

func (*SyncWriter) Write

func (sw *SyncWriter) Write(p []byte) (int, error)

type TableSerializer

type TableSerializer struct{}

func (*TableSerializer) Serialize

func (s *TableSerializer) Serialize(m proto.Message) ([]byte, error)

type WatchFunc

type WatchFunc func(StopFunc) error

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{}

func (*YamlSerializer) Serialize

func (s *YamlSerializer) Serialize(m proto.Message) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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