cmdutil

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var DefaultTabWriter = tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

func FormatPhase

func FormatPhase(phase 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 Watch

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

Types

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
const (
	ColorReset Color = "\x1b[0000m"
	FgRed      Color = "\x1b[38;5;001m"
	FgGreen    Color = "\x1b[38;5;034m"
	FgYellow   Color = "\x1b[38;5;011m"
	FgCyan     Color = "\x1b[38;5;036m"
	FgGrey245  Color = "\x1b[38;5;245m"
	FgPurple   Color = "\x1b[38;5;092m"
)

type Dashboard

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

Dashboard holds all services + rendering logic

func NewDashboard

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

NewDashboard creates the dashboard with one ServiceState per name.

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 runs the renderer until ctx is done.

func (*Dashboard) SetDetails added in v0.0.11

func (d *Dashboard) SetDetails(idx int, lines []Detail)

SetDetails assigns a new slice, overwriting any other Detail sets previously used. If you want to update an existing line then use UpdateDetail()

func (*Dashboard) Update

func (d *Dashboard) Update(idx int, fn func(s *ServiceState))

Update lets workers mutate a single service under lock.

func (*Dashboard) UpdateDetails added in v0.0.11

func (d *Dashboard) UpdateDetails(idx int, key, value string)

UpdateDetails inserts a new line. If a line with same key exists then that line is updated. So two lines with the same key cannot exist in the slice.

func (*Dashboard) UpdateText added in v0.0.11

func (d *Dashboard) UpdateText(idx int, text string)

UpdateText 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 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 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 Option added in v0.0.11

type Option func(*Dashboard)

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 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 Serializer

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

func SerializerFor

func SerializerFor(s string) (Serializer, error)

type ServiceState

type ServiceState struct {
	Name   string
	Text   string
	Color  Color
	Done   bool
	Failed bool

	Details []Detail
	// contains filtered or unexported fields
}

ServiceState represents One line in the dashboard

type StopFunc

type StopFunc func()

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)

Jump to

Keyboard shortcuts

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