Documentation ¶
Index ¶
- Variables
- type DynamicSpinner
- type JSON
- type PrintFormat
- type Printer
- type ResourcePrinter
- type ResourcePrinterOption
- type Spinner
- type StaticSpinner
- type Status
- type StatusPrinter
- func (s *StatusPrinter) Debugf(format string, a ...interface{})
- func (s *StatusPrinter) End(success bool)
- func (s *StatusPrinter) InfoStructFields(header string, data any) error
- func (s *StatusPrinter) InfoWithBody(header, body string)
- func (s *StatusPrinter) Infof(format string, a ...interface{})
- func (s *StatusPrinter) Step(stageFmt string, args ...interface{})
- func (s *StatusPrinter) Writer() io.Writer
- type YAML
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidFormatType = fmt.Errorf("invalid output format type")
ErrInvalidFormatType is returned when an unsupported format type is used
Functions ¶
This section is empty.
Types ¶
type DynamicSpinner ¶
type DynamicSpinner struct {
// contains filtered or unexported fields
}
DynamicSpinner is suitable for smart terminals which support animations (control cursor location, color etc.).
func NewDynamicSpinner ¶
func NewDynamicSpinner(w *os.File) *DynamicSpinner
NewDynamicSpinner returns a new DynamicSpinner instance.
func (*DynamicSpinner) Active ¶
func (d *DynamicSpinner) Active() bool
Active returns whether the spinner is currently active.
func (*DynamicSpinner) Start ¶
func (d *DynamicSpinner) Start(stage string)
Start activates the spinner with a given name.
func (*DynamicSpinner) Stop ¶
func (d *DynamicSpinner) Stop(msg string)
Stop deactivates the spinner with a given message.
type PrintFormat ¶ added in v1.4.0
type PrintFormat string
PrintFormat is a type for capturing supported output formats. Implements pflag.Value interface.
const ( // JSONFormat represents JSON data format. JSONFormat PrintFormat = "json" // YAMLFormat represents YAML data format. YAMLFormat PrintFormat = "yaml" )
func (PrintFormat) IsValid ¶ added in v1.4.0
func (o PrintFormat) IsValid() bool
IsValid returns true if PrintFormat is valid.
func (*PrintFormat) Set ¶ added in v1.4.0
func (o *PrintFormat) Set(in string) error
Set format type to a given input. Required by pflag.Value interface.
func (PrintFormat) String ¶ added in v1.4.0
func (o PrintFormat) String() string
String returns the string representation of the Format. Required by pflag.Value interface.
func (*PrintFormat) Type ¶ added in v1.4.0
func (o *PrintFormat) Type() string
Type returns data type. Required by pflag.Value interface.
type Printer ¶ added in v1.4.0
type Printer interface { // Print receives an object, formats it and prints it to a writer. Print(in interface{}, w io.Writer) error }
Printer is an interface that knows how to print objects.
type ResourcePrinter ¶ added in v1.4.0
type ResourcePrinter struct {
// contains filtered or unexported fields
}
ResourcePrinter provides functionality to print a given resource in requested format. Can be configured with pflag.FlagSet.
func NewForResource ¶ added in v1.4.0
func NewForResource(w io.Writer, opts ...ResourcePrinterOption) *ResourcePrinter
NewForResource returns a new ResourcePrinter instance.
func (*ResourcePrinter) Print ¶ added in v1.4.0
func (r *ResourcePrinter) Print(in interface{}) error
Print prints received object in requested format.
func (*ResourcePrinter) PrintFormat ¶ added in v1.4.0
func (r *ResourcePrinter) PrintFormat() PrintFormat
PrintFormat returns default print format type.
func (*ResourcePrinter) RegisterFlags ¶ added in v1.4.0
func (r *ResourcePrinter) RegisterFlags(flags *pflag.FlagSet)
RegisterFlags registers ResourcePrinter terminal flags.
type ResourcePrinterOption ¶ added in v1.4.0
type ResourcePrinterOption func(*ResourcePrinter)
ResourcePrinterOption allows ResourcePrinter instance customization.
func WithDefaultOutputFormat ¶ added in v1.4.0
func WithDefaultOutputFormat(format PrintFormat) ResourcePrinterOption
WithDefaultOutputFormat sets a default format type.
func WithJSON ¶ added in v1.4.0
func WithJSON() ResourcePrinterOption
WithJSON registers JSON format type.
func WithYAML ¶ added in v1.4.0
func WithYAML() ResourcePrinterOption
WithYAML registers YAML format type.
type StaticSpinner ¶
type StaticSpinner struct {
// contains filtered or unexported fields
}
StaticSpinner is suitable for non-smart terminals.
func NewStaticSpinner ¶
func NewStaticSpinner(w io.Writer) *StaticSpinner
NewStaticSpinner returns a new StaticSpinner instance.
func (*StaticSpinner) Active ¶
func (s *StaticSpinner) Active() bool
Active returns whether the spinner is currently active.
func (*StaticSpinner) Start ¶
func (s *StaticSpinner) Start(stage string)
Start activates the spinner with a given name.
func (*StaticSpinner) Stop ¶
func (s *StaticSpinner) Stop(msg string)
Stop deactivates the spinner with a given message.
type Status ¶
type Status interface { Step(stageFmt string, args ...interface{}) End(success bool) Infof(format string, a ...interface{}) InfoWithBody(header, body string) Writer() io.Writer }
Status defines status printer methods. Allows us to use different status printers.
type StatusPrinter ¶
StatusPrinter provides functionality to display steps progress in terminal.
func NewStatus ¶
func NewStatus(w io.Writer, header string) *StatusPrinter
NewStatus returns a new Status instance.
func (*StatusPrinter) Debugf ¶
func (s *StatusPrinter) Debugf(format string, a ...interface{})
Debugf prints a given debug message without spinner animation. It prints it only if verbose flag was specified.
func (*StatusPrinter) End ¶
func (s *StatusPrinter) End(success bool)
End marks started step as completed.
func (*StatusPrinter) InfoStructFields ¶
func (s *StatusPrinter) InfoStructFields(header string, data any) error
InfoStructFields prints a given struct with key-value layout.
func (*StatusPrinter) InfoWithBody ¶
func (s *StatusPrinter) InfoWithBody(header, body string)
InfoWithBody prints a given info with a given body and without spinner animation.
func (*StatusPrinter) Infof ¶
func (s *StatusPrinter) Infof(format string, a ...interface{})
Infof prints a given info without spinner animation.
func (*StatusPrinter) Step ¶
func (s *StatusPrinter) Step(stageFmt string, args ...interface{})
Step starts spinner for a given step.
func (*StatusPrinter) Writer ¶
func (s *StatusPrinter) Writer() io.Writer
Writer returns underlying io.Writer