Documentation ¶
Index ¶
- type Err
- type Msg
- func Debug(args ...any) Msg
- func Debugf(format string, a ...any) Msg
- func Error(args ...any) Msg
- func Errorf(format string, a ...any) Msg
- func Info(args ...any) Msg
- func Infof(format string, a ...any) Msg
- func Log(args ...any) Msg
- func Logf(format string, a ...any) Msg
- func Success(args ...any) Msg
- func Successf(format string, a ...any) Msg
- func Warn(args ...any) Msg
- func Warnf(format string, a ...any) Msg
- type PrintCLIErrorer
- type Printer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Err ¶
type Err struct { // Err is a string to avoid punctuation linting Err string // setting ExcludeDefaultError to true will cause the PrintCLIError method to only print the contents of Messages // by default PrintCLIError first prints the contents of Err, followed by the contents of Messages ExcludeDefaultError bool // Messages are items which implement the clio.Printer interface. // when PrintCLIError is called, each of the messages Print() method is called in order of appearence in the slice Messages []Printer }
Err is a CLI error. Calling PrintCLIError() on it will print error messages to the console.
func New ¶
New creates a new CLI error. You can append additional log messages to the error by adding fields to the 'msgs' argument.
Example:
clierr.New("something bad happened", clierr.Error("some extra context here"))
func (*Err) Error ¶
Error implements the error interface. It uses the default message of the wrapped error.
func (*Err) PrintCLIError ¶
func (e *Err) PrintCLIError()
PrintCLIError prints the error message and then any messages in order from the slice The indended use is to surface errors with useful messages then os.Exit without having to place os.Exit within methods other than the cli main function
err := CLIError{Err: "new error", Messages: []Printer{Log("hello world")}} err.PrintCLIError() // produces [✘] new error hello world
type Msg ¶
func Debug ¶
Debug adds a debug message. This message will only be displayed if the logging level is set to 'debug'.
func Debugf ¶
Debugf adds a formatted debug message. This message will only be displayed if the logging level is set to 'debug'.
func Logf ¶
Logf adds a formatted log message. Warning: this will be printed to stdout, rather than stderr.
type PrintCLIErrorer ¶
type PrintCLIErrorer interface {
PrintCLIError()
}