printer

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package printer defines funtionality for "printing" text to an io.Writer e.g. os.Stdout, os.Stderr etc. with a consistent style for errors, warnings, information etc.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// Stderr is the default stderr printer
	Stderr = NewPrinter(os.Stderr)
	// Stdout is the default stdout printer
	Stdout = NewPrinter(os.Stdout)
)

Functions

This section is empty.

Types

type Printer

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

Printer encapuslates an io.Writer

func NewPrinter

func NewPrinter(w io.Writer) *Printer

NewPrinter creates a new Printer with the provider io.Writer e.g.: stdio, stderr, file etc.

Example
p := NewPrinter(os.Stdout)
p.Println("Doing something")
p.Warn("doing something fishy")
p.ErrorWithDetails(
	"failed to find fish",
	stderrors.New("error 1"),
)
Output:

Doing something
Warning: doing something fishy
Error: failed to find fish
> error 1

func (*Printer) Error added in v0.4.5

func (p *Printer) Error(arg any)

Error prints a message with a "Error:" prefix. The prefix is printed in the boldRed style.

func (*Printer) ErrorWithDetails added in v0.4.5

func (p *Printer) ErrorWithDetails(title string, err error)

ErrorWithDetails prints an error with a title and the underlying error. If the error contains multiple error items, each error is printed with a `->` prefix. e.g.: Error: parsing failed -> somefile.tm:8,3-7: terramate schema error: unrecognized attribute -> somefile.tm:9,4-7: terramate schema error: unrecognized block

func (*Printer) Errorf added in v0.6.1

func (p *Printer) Errorf(format string, a ...any)

Errorf is short for Error(fmt.Sprintf(...)).

func (*Printer) Fatal added in v0.5.0

func (p *Printer) Fatal(err any)

Fatal prints an error with a title and the underlying error and calls os.Exit(1).

func (*Printer) FatalWithDetails added in v0.6.1

func (p *Printer) FatalWithDetails(title string, err error)

FatalWithDetails prints an error with a title and the underlying error and calls os.Exit(1).

func (*Printer) Fatalf added in v0.6.1

func (p *Printer) Fatalf(format string, a ...any)

Fatalf is short for Fatal(fmt.Sprintf(...)).

func (*Printer) Println

func (p *Printer) Println(msg string)

Println prints a message to the io.Writer

func (*Printer) Success added in v0.4.5

func (p *Printer) Success(msg string)

Success prints a message in the boldGreen style

func (*Printer) Successf added in v0.6.1

func (p *Printer) Successf(format string, a ...any)

Successf is short for Success(fmt.Sprintf(...)).

func (*Printer) Warn added in v0.4.5

func (p *Printer) Warn(arg any)

Warn prints a message with a "Warning:" prefix. The prefix is printed in the boldYellow style.

func (*Printer) WarnWithDetails added in v0.4.5

func (p *Printer) WarnWithDetails(title string, err error)

WarnWithDetails is similar to ErrorWithDetailsln but prints a warning instead

func (*Printer) Warnf added in v0.6.1

func (p *Printer) Warnf(format string, a ...any)

Warnf is short for Warn(fmt.Sprintf(...)).

Jump to

Keyboard shortcuts

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