Documentation ¶
Index ¶
- Constants
- Variables
- func Color(code, msg string) string
- func Debug(msg string, args ...interface{})
- func Die(msg string, args ...interface{})
- func Err(msg string, args ...interface{})
- func ExitCode(e int) int
- func HasErrored() bool
- func Info(msg string, args ...interface{})
- func Msg(msg string, args ...interface{})
- func Print(msg string)
- func Puts(msg string, args ...interface{})
- func Warn(msg string, args ...interface{})
- type Messenger
- func (m *Messenger) Color(code, msg string) string
- func (m *Messenger) Debug(msg string, args ...interface{})
- func (m *Messenger) Die(msg string, args ...interface{})
- func (m *Messenger) Err(msg string, args ...interface{})
- func (m *Messenger) ExitCode(e int) int
- func (m *Messenger) HasErrored() bool
- func (m *Messenger) Info(msg string, args ...interface{})
- func (m *Messenger) Msg(msg string, args ...interface{})
- func (m *Messenger) Print(msg string)
- func (m *Messenger) Puts(msg string, args ...interface{})
- func (m *Messenger) Warn(msg string, args ...interface{})
Constants ¶
const ( Blue = "0;34" Red = "0;31" Green = "0;32" Yellow = "0;33" Cyan = "0;36" Pink = "1;35" )
These contanstants map to color codes for shell scripts making them human readable.
Variables ¶
var Default = NewMessenger()
Default contains a default Messenger used by package level functions
Functions ¶
func Color ¶
Color returns a string in a certain color if colors are enabled and available on that platform.
func Debug ¶
func Debug(msg string, args ...interface{})
Debug logs debug information using the Default Messenger
func Die ¶
func Die(msg string, args ...interface{})
Die prints an error message and immediately exits the application using the Default Messenger. If PanicOnDie is set to true a panic will occur instead of os.Exit being called.
func ExitCode ¶
ExitCode sets the exit code used by Die using the Default Messenger.
The default is 1.
Returns the old error code.
func HasErrored ¶
func HasErrored() bool
HasErrored returns if Error has been called on the Default Messenger.
This is useful if you want to known if Error was called to exit with a non-zero exit code.
func Info ¶
func Info(msg string, args ...interface{})
Info logs information using the Default Messenger
func Msg ¶
func Msg(msg string, args ...interface{})
Msg prints a message with optional arguments, that can be printed, of varying types using the Default Messenger.
func Print ¶
func Print(msg string)
Print prints exactly the string given using the Default Messenger.
It prints to Stdout.
Types ¶
type Messenger ¶
type Messenger struct { sync.Mutex // Quiet, if true, suppresses chatty levels, like Info. Quiet bool // IsDebugging, if true, shows verbose levels, like Debug. IsDebugging bool // NoColor, if true, will not use color in the output. NoColor bool // Stdout is the location where this prints output. Stdout io.Writer // Stderr is the location where this prints logs. Stderr io.Writer // PanicOnDie if true Die() will panic instead of exiting. PanicOnDie bool // contains filtered or unexported fields }
Messenger provides the underlying implementation that displays output to users.
func NewMessenger ¶
func NewMessenger() *Messenger
NewMessenger creates a default Messenger to display output.
func (*Messenger) Color ¶
Color returns a string in a certain color. The first argument is a string containing the color code or a constant from the table above mapped to a code.
The following will print the string "Foo" in yellow:
fmt.Print(Color(Yellow, "Foo"))
func (*Messenger) Die ¶
Die prints an error message and immediately exits the application. If PanicOnDie is set to true a panic will occur instead of os.Exit being called.
func (*Messenger) ExitCode ¶
ExitCode sets the exit code used by Die.
The default is 1.
Returns the old error code.
func (*Messenger) HasErrored ¶
HasErrored returns if Error has been called.
This is useful if you want to known if Error was called to exit with a non-zero exit code.
func (*Messenger) Msg ¶
Msg prints a message with optional arguments, that can be printed, of varying types.