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 PromptUntil(opts []string) (string, error)
- func PromptUntilYorN() bool
- func Puts(msg string, args ...interface{})
- func Verbose(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) PromptUntil(opts []string) (string, error)
- func (m *Messenger) PromptUntilYorN() bool
- func (m *Messenger) Puts(msg string, args ...interface{})
- func (m *Messenger) Verbose(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.
func PromptUntil ¶
PromptUntil provides a prompt until one of the passed in strings has been entered and return is hit. Note, the comparisons are case insensitive meaning Y == y. The returned value is the one from the passed in options (same case). Uses the default setup.
func PromptUntilYorN ¶
func PromptUntilYorN() bool
PromptUntilYorN provides a prompt until the user chooses yes or no. This is not case sensitive and they can input other options such as Y or N. In the response Yes is bool true and No is bool false. Uses the default setup.
func Puts ¶
func Puts(msg string, args ...interface{})
Puts formats a message and then prints to Stdout using the Default Messenger.
It does not prefix the message, does not color it, or otherwise decorate it.
It does add a line feed.
Types ¶
type Messenger ¶
type Messenger struct { sync.Mutex // Quiet, if true, suppresses chatty levels, like Info. Quiet bool // IsDebugging, if true, shows Debug. IsDebugging bool // IsVerbose, if true, shows detailed informational messages. IsVerbose 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 // Stdin is the location where input is read. Stdin io.Reader // 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.
func (*Messenger) PromptUntil ¶
PromptUntil provides a prompt until one of the passed in strings has been entered and return is hit. Note, the comparisons are case insensitive meaning Y == y. The returned value is the one from the passed in options (same case).
func (*Messenger) PromptUntilYorN ¶
PromptUntilYorN provides a prompt until the user chooses yes or no. This is not case sensitive and they can input other options such as Y or N. In the response Yes is bool true and No is bool false.
func (*Messenger) Puts ¶
Puts formats a message and then prints to Stdout.
It does not prefix the message, does not color it, or otherwise decorate it.
It does add a line feed.