output

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 12 Imported by: 8

Documentation

Overview

Package output implements a printer used to output the messages. It is based on the pterm library and is extensible.

Index

Constants

View Source
const (
	// LogFormatColor formatting option for logs.
	LogFormatColor = "color"
	// LogFormatText formatting option for logs.
	LogFormatText = "text"
	// LogFormatJSON formatting otion for logs.
	LogFormatJSON = "json"
)
View Source
const (
	// LogLevelInfo level option for logs.
	LogLevelInfo = "info"
	// LogLevelWarn level opiton for logs.
	LogLevelWarn = "warn"
	// LogLevelDebug level option for logs.
	LogLevelDebug = "debug"
	// LogLevelTrace level option for logs.
	LogLevelTrace = "trace"
)

Variables

This section is empty.

Functions

func ExitOnErr

func ExitOnErr(p *Printer, err error)

ExitOnErr aborts the execution in case of errors, and prints the error using the configured printer.

func NewProgressBar added in v0.7.0

func NewProgressBar() pterm.ProgressbarPrinter

NewProgressBar returns a new progress bar printer.

Types

type LogFormat added in v0.8.0

type LogFormat struct {
	*enum.Enum
}

LogFormat data structure for log-format flag.

func NewLogFormat added in v0.8.0

func NewLogFormat() *LogFormat

NewLogFormat returns a new Enum configured for the log formats flag.

func (*LogFormat) ToPtermFormatter added in v0.8.0

func (lg *LogFormat) ToPtermFormatter() pterm.LogFormatter

ToPtermFormatter converts the current formatter to pterm.LogFormatter.

type LogLevel added in v0.8.0

type LogLevel struct {
	*enum.Enum
}

LogLevel data structure for log-level flag.

func NewLogLevel added in v0.8.0

func NewLogLevel() *LogLevel

NewLogLevel returns a new Enum configured for the log level flag.

func (*LogLevel) ToPtermLogLevel added in v0.8.0

func (ll *LogLevel) ToPtermLogLevel() pterm.LogLevel

ToPtermLogLevel converts the current log level to pterm.LogLevel.

type Printer

type Printer struct {
	Logger         *pterm.Logger
	DefaultText    *pterm.BasicTextPrinter
	TablePrinter   *pterm.TablePrinter
	ProgressBar    *pterm.ProgressbarPrinter
	Spinner        *pterm.SpinnerPrinter
	DisableStyling bool
}

Printer used by all commands to output messages. If a commands needs a new format for its output add it here.

func NewPrinter

func NewPrinter(logLevel pterm.LogLevel, logFormatter pterm.LogFormatter, writer io.Writer) *Printer

NewPrinter returns a printer ready to be used.

func (*Printer) CheckErr

func (p *Printer) CheckErr(err error)

CheckErr prints a user-friendly error based on the active printer.

func (*Printer) FormatTitleAsLoggerInfo added in v0.7.0

func (p *Printer) FormatTitleAsLoggerInfo(msg string) string

FormatTitleAsLoggerInfo returns the msg formatted as been printed by the Info logger.

func (*Printer) PrintTable

func (p *Printer) PrintTable(header TableHeader, data [][]string) error

PrintTable is a helper used to print data in table format.

func (Printer) WithWriter

func (p Printer) WithWriter(writer io.Writer) *Printer

WithWriter sets the writer for the current printer.

type ProgressTracker

type ProgressTracker struct {
	oras.Target
	*Printer
	// contains filtered or unexported fields
}

ProgressTracker tracks the progress of pull and push operations.

func NewProgressTracker

func NewProgressTracker(printer *Printer, target oras.Target, msg string) *ProgressTracker

NewProgressTracker returns a new ProgressTracker ready to be used.

func (*ProgressTracker) Exists

func (t *ProgressTracker) Exists(ctx context.Context, target v1.Descriptor) (bool, error)

Exists if the layer already exists it prints out the correct message.

func (*ProgressTracker) Push

func (t *ProgressTracker) Push(ctx context.Context, expected v1.Descriptor, content io.Reader) error

Push reimplements the Push function of the oras.Target interface adding the needed logic for the progress bar.

type TableHeader

type TableHeader int

TableHeader is used to print out the correct header for a command.

const (
	// ArtifactSearch identifies the header for artifact search.
	ArtifactSearch TableHeader = iota
	// IndexList identifies the header for index list.
	IndexList
	// ArtifactInfo identifies the header for artifact info.
	ArtifactInfo
)

type Tracker

type Tracker func(target oras.Target) oras.Target

Tracker get an oras.Target and returns a new target that implements the tracker logic.

func NewTracker

func NewTracker(printer *Printer, msg string) Tracker

NewTracker returns a new Tracker.

Jump to

Keyboard shortcuts

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