Documentation ¶
Overview ¶
Package ui is an abstraction on dealing with writing and reading from ui / cli. Do not want to clutter the pkg package with log entries as it makes it difficult to reuse. So ui package abstracts it away and leaves it to those use packages to implement a handler
Concept is based on github.com/mitchellh/cli package, but changed a bit to include headers etc
Index ¶
- func Ask(query string) (string, error)
- func AskSecret(query string) (string, error)
- func Debug(msg string, args ...interface{})
- func Error(msg string, args ...interface{})
- func Fatal(msg string, args ...interface{})
- func Header(msg string)
- func Info(msg string, args ...interface{})
- func NewLine()
- func Output(msg string, args ...interface{})
- func Separator(title string)
- func SetHandler(hnd Handler)
- func SetLevel(newLevel Level)
- func Warn(msg string, args ...interface{})
- type CliHandler
- func (hnd *CliHandler) Ask(query string) (string, error)
- func (hnd *CliHandler) AskSecret(query string) (string, error)
- func (hnd *CliHandler) Debug(msg string, args ...interface{})
- func (hnd *CliHandler) Error(msg string, args ...interface{})
- func (hnd *CliHandler) Fatal(msg string, args ...interface{})
- func (hnd *CliHandler) Header(msg string)
- func (hnd *CliHandler) Info(msg string, args ...interface{})
- func (hnd *CliHandler) NewLine()
- func (hnd *CliHandler) Output(msg string, args ...interface{})
- func (hnd *CliHandler) Separator(title string)
- func (hnd *CliHandler) Warn(msg string, args ...interface{})
- type Handler
- type Level
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
func Debug(msg string, args ...interface{})
Debug will print a debug message, if debugging is activated
func Fatal ¶
func Fatal(msg string, args ...interface{})
Fatal prints a fatal message and should always exit!
func Header ¶
func Header(msg string)
Header prints a header, can be bold etc. Implementation can decide how a header should be made
func Info ¶
func Info(msg string, args ...interface{})
Info will print an information message. Should not be formatted any special way
func SetHandler ¶
func SetHandler(hnd Handler)
SetHandler assigns a new handler overriding current (default is cli handler)
Types ¶
type CliHandler ¶
type CliHandler struct { Reader io.Reader OutputWriter io.Writer LogWriter io.Writer // contains filtered or unexported fields }
CliHandler is the default handler and will write to stdout / stderr
func (*CliHandler) AskSecret ¶
func (hnd *CliHandler) AskSecret(query string) (string, error)
AskSecret as for secret input
func (*CliHandler) Debug ¶
func (hnd *CliHandler) Debug(msg string, args ...interface{})
Debug prints a debug message
func (*CliHandler) Error ¶
func (hnd *CliHandler) Error(msg string, args ...interface{})
Error prints message
func (*CliHandler) Fatal ¶
func (hnd *CliHandler) Fatal(msg string, args ...interface{})
Fatal prints message and makes sure to fail
func (*CliHandler) Info ¶
func (hnd *CliHandler) Info(msg string, args ...interface{})
Info prints message to standard out
func (*CliHandler) NewLine ¶
func (hnd *CliHandler) NewLine()
NewLine creates a new line, except if previous line was a new line. Do not want 2 new lines after another
func (*CliHandler) Output ¶
func (hnd *CliHandler) Output(msg string, args ...interface{})
Output prints to output writer
func (*CliHandler) Separator ¶
func (hnd *CliHandler) Separator(title string)
Separator does nothing
func (*CliHandler) Warn ¶
func (hnd *CliHandler) Warn(msg string, args ...interface{})
Warn prints message
type Handler ¶
type Handler interface { // Ask for input from user Ask(query string) (string, error) // AskSecret will ask for a secret input, not showing what is typed AskSecret(query string) (string, error) Debug(msg string, args ...interface{}) Info(msg string, args ...interface{}) Warn(msg string, args ...interface{}) Error(msg string, args ...interface{}) Fatal(msg string, args ...interface{}) // Output writes to stdout so it can be piped to subsequent commands Output(msg string, args ...interface{}) // Header prints a header, can be bold etc. Implementation can decide how a header // should be made. Should always be printed as info message Header(msg string) // Separator between elements. Should always be printed as info message Separator(title string) // NewLine adds a new line if necessary NewLine() }
Handler for ui commands. Can ask for input, output messages and enforce a specific format.
type Level ¶
type Level int
Level of output
func ParseLevel ¶
ParseLevel returns the level defined by string. If it is not able to parse the level string it will return Info as default level
Since there is no trace level that is interpreted as debug