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 ¶
- Variables
- type Printer
- func (p *Printer) Error(arg any)
- func (p *Printer) ErrorWithDetails(title string, err error)
- func (p *Printer) Errorf(format string, a ...any)
- func (p *Printer) Fatal(err any)
- func (p *Printer) FatalWithDetails(title string, err error)
- func (p *Printer) Fatalf(format string, a ...any)
- func (p *Printer) Println(msg string)
- func (p *Printer) Success(msg string)
- func (p *Printer) Successf(format string, a ...any)
- func (p *Printer) Warn(arg any)
- func (p *Printer) WarnWithDetails(title string, err error)
- func (p *Printer) Warnf(format string, a ...any)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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
Error prints a message with a "Error:" prefix. The prefix is printed in the boldRed style.
func (*Printer) ErrorWithDetails ¶ added in v0.4.5
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) Fatal ¶ added in v0.5.0
Fatal prints an error with a title and the underlying error and calls os.Exit(1).
func (*Printer) FatalWithDetails ¶ added in v0.6.1
FatalWithDetails prints an error with a title and the underlying error and calls os.Exit(1).
func (*Printer) Warn ¶ added in v0.4.5
Warn prints a message with a "Warning:" prefix. The prefix is printed in the boldYellow style.
func (*Printer) WarnWithDetails ¶ added in v0.4.5
WarnWithDetails is similar to ErrorWithDetailsln but prints a warning instead