Documentation ¶
Overview ¶
Package ui will provide hooks into STDOUT, STDERR and STDIN. It will also handle translation as necessary.
This package is explicitly designed for the CF CLI and is *not* to be used by any package outside of the commands package.
Index ¶
- Constants
- func GetTranslationFunc(config Config) (i18n.TranslateFunc, error)
- func SanitizeJSON(raw []byte) (map[string]interface{}, error)
- type Config
- type LogMessage
- type RequestLoggerFileWriter
- func (display *RequestLoggerFileWriter) DisplayBody(_ []byte) error
- func (display RequestLoggerFileWriter) DisplayDump(dump string) error
- func (display *RequestLoggerFileWriter) DisplayHeader(name string, value string) error
- func (display *RequestLoggerFileWriter) DisplayHost(name string) error
- func (display *RequestLoggerFileWriter) DisplayJSONBody(body []byte) error
- func (display *RequestLoggerFileWriter) DisplayRequestHeader(method string, uri string, httpProtocol string) error
- func (display *RequestLoggerFileWriter) DisplayResponseHeader(httpProtocol string, status string) error
- func (display *RequestLoggerFileWriter) DisplayType(name string, requestDate time.Time) error
- func (display *RequestLoggerFileWriter) HandleInternalError(err error)
- func (display *RequestLoggerFileWriter) Start() error
- func (display *RequestLoggerFileWriter) Stop() error
- type RequestLoggerTerminalDisplay
- func (display *RequestLoggerTerminalDisplay) DisplayBody(_ []byte) error
- func (display RequestLoggerTerminalDisplay) DisplayDump(dump string) error
- func (display *RequestLoggerTerminalDisplay) DisplayHeader(name string, value string) error
- func (display *RequestLoggerTerminalDisplay) DisplayHost(name string) error
- func (display *RequestLoggerTerminalDisplay) DisplayJSONBody(body []byte) error
- func (display *RequestLoggerTerminalDisplay) DisplayRequestHeader(method string, uri string, httpProtocol string) error
- func (display *RequestLoggerTerminalDisplay) DisplayResponseHeader(httpProtocol string, status string) error
- func (display *RequestLoggerTerminalDisplay) DisplayType(name string, requestDate time.Time) error
- func (display *RequestLoggerTerminalDisplay) HandleInternalError(err error)
- func (display *RequestLoggerTerminalDisplay) Start() error
- func (display *RequestLoggerTerminalDisplay) Stop() error
- type TranslatableError
- type UI
- func (ui *UI) DisplayBoolPrompt(defaultResponse bool, template string, ...) (bool, error)
- func (ui *UI) DisplayError(err error)
- func (ui *UI) DisplayHeader(text string)
- func (ui *UI) DisplayInstancesTableForApp(table [][]string)
- func (ui *UI) DisplayKeyValueTable(prefix string, table [][]string, padding int)
- func (ui *UI) DisplayKeyValueTableForApp(table [][]string)
- func (ui *UI) DisplayLogMessage(message LogMessage, displayHeader bool)
- func (ui *UI) DisplayNewline()
- func (ui *UI) DisplayNonWrappingTable(prefix string, table [][]string, padding int)
- func (ui *UI) DisplayOK()
- func (ui *UI) DisplayTableWithHeader(prefix string, table [][]string, padding int)
- func (ui *UI) DisplayText(template string, templateValues ...map[string]interface{})
- func (ui *UI) DisplayTextWithFlavor(template string, templateValues ...map[string]interface{})
- func (ui *UI) DisplayWarning(template string, templateValues ...map[string]interface{})
- func (ui *UI) DisplayWarnings(warnings []string)
- func (ui *UI) RequestLoggerFileWriter(filePaths []string) *RequestLoggerFileWriter
- func (ui *UI) RequestLoggerTerminalDisplay() *RequestLoggerTerminalDisplay
- func (ui *UI) TranslateText(template string, templateValues ...map[string]interface{}) string
- func (ui *UI) UserFriendlyDate(input time.Time) string
Constants ¶
const LogTimestampFormat = "2006-01-02T15:04:05.00-0700"
const RedactedValue = "[PRIVATE DATA HIDDEN]"
Variables ¶
This section is empty.
Functions ¶
func GetTranslationFunc ¶
func GetTranslationFunc(config Config) (i18n.TranslateFunc, error)
GetTranslationFunc will return back a function that can be used to translate strings into the currently set locale.
func SanitizeJSON ¶
Types ¶
type Config ¶
type Config interface { // ColorEnabled enables or disabled color ColorEnabled() configv3.ColorSetting // Locale is the language to translate the output to Locale() string // IsTTY returns true when the ui has a TTY IsTTY() bool // TerminalWidth returns the width of the terminal TerminalWidth() int }
Config is the UI configuration
type LogMessage ¶
type LogMessage interface { Message() string Type() string Timestamp() time.Time SourceType() string SourceInstance() string }
LogMessage is a log response representing one to many joined lines of a log message.
type RequestLoggerFileWriter ¶
type RequestLoggerFileWriter struct {
// contains filtered or unexported fields
}
func (*RequestLoggerFileWriter) DisplayBody ¶
func (display *RequestLoggerFileWriter) DisplayBody(_ []byte) error
func (RequestLoggerFileWriter) DisplayDump ¶
func (display RequestLoggerFileWriter) DisplayDump(dump string) error
func (*RequestLoggerFileWriter) DisplayHeader ¶
func (display *RequestLoggerFileWriter) DisplayHeader(name string, value string) error
func (*RequestLoggerFileWriter) DisplayHost ¶
func (display *RequestLoggerFileWriter) DisplayHost(name string) error
func (*RequestLoggerFileWriter) DisplayJSONBody ¶
func (display *RequestLoggerFileWriter) DisplayJSONBody(body []byte) error
func (*RequestLoggerFileWriter) DisplayRequestHeader ¶
func (display *RequestLoggerFileWriter) DisplayRequestHeader(method string, uri string, httpProtocol string) error
func (*RequestLoggerFileWriter) DisplayResponseHeader ¶
func (display *RequestLoggerFileWriter) DisplayResponseHeader(httpProtocol string, status string) error
func (*RequestLoggerFileWriter) DisplayType ¶
func (display *RequestLoggerFileWriter) DisplayType(name string, requestDate time.Time) error
func (*RequestLoggerFileWriter) HandleInternalError ¶
func (display *RequestLoggerFileWriter) HandleInternalError(err error)
func (*RequestLoggerFileWriter) Start ¶
func (display *RequestLoggerFileWriter) Start() error
func (*RequestLoggerFileWriter) Stop ¶
func (display *RequestLoggerFileWriter) Stop() error
type RequestLoggerTerminalDisplay ¶
type RequestLoggerTerminalDisplay struct {
// contains filtered or unexported fields
}
func (*RequestLoggerTerminalDisplay) DisplayBody ¶
func (display *RequestLoggerTerminalDisplay) DisplayBody(_ []byte) error
func (RequestLoggerTerminalDisplay) DisplayDump ¶
func (display RequestLoggerTerminalDisplay) DisplayDump(dump string) error
func (*RequestLoggerTerminalDisplay) DisplayHeader ¶
func (display *RequestLoggerTerminalDisplay) DisplayHeader(name string, value string) error
func (*RequestLoggerTerminalDisplay) DisplayHost ¶
func (display *RequestLoggerTerminalDisplay) DisplayHost(name string) error
func (*RequestLoggerTerminalDisplay) DisplayJSONBody ¶
func (display *RequestLoggerTerminalDisplay) DisplayJSONBody(body []byte) error
func (*RequestLoggerTerminalDisplay) DisplayRequestHeader ¶
func (display *RequestLoggerTerminalDisplay) DisplayRequestHeader(method string, uri string, httpProtocol string) error
func (*RequestLoggerTerminalDisplay) DisplayResponseHeader ¶
func (display *RequestLoggerTerminalDisplay) DisplayResponseHeader(httpProtocol string, status string) error
func (*RequestLoggerTerminalDisplay) DisplayType ¶
func (display *RequestLoggerTerminalDisplay) DisplayType(name string, requestDate time.Time) error
func (*RequestLoggerTerminalDisplay) HandleInternalError ¶
func (display *RequestLoggerTerminalDisplay) HandleInternalError(err error)
func (*RequestLoggerTerminalDisplay) Start ¶
func (display *RequestLoggerTerminalDisplay) Start() error
func (*RequestLoggerTerminalDisplay) Stop ¶
func (display *RequestLoggerTerminalDisplay) Stop() error
type TranslatableError ¶
type TranslatableError interface { // Returns the untranslated error string Error() string Translate(func(string, ...interface{}) string) string }
TranslatableError it wraps the error interface adding a way to set the translation function on the error
type UI ¶
type UI struct { // In is the input buffer In io.Reader // Out is the output buffer Out io.Writer // Err is the error buffer Err io.Writer IsTTY bool TerminalWidth int TimezoneLocation *time.Location // contains filtered or unexported fields }
UI is interface to interact with the user
func NewTestUI ¶
NewTestUI will return a UI object where Out, In, and Err are customizable, and colors are disabled
func NewUI ¶
NewUI will return a UI object where Out is set to STDOUT, In is set to STDIN, and Err is set to STDERR
func (*UI) DisplayBoolPrompt ¶
func (ui *UI) DisplayBoolPrompt(defaultResponse bool, template string, templateValues ...map[string]interface{}) (bool, error)
DisplayBoolPrompt outputs the prompt and waits for user input. It only allows for a boolean response. A default boolean response can be set with defaultResponse.
func (*UI) DisplayError ¶
DisplayError outputs the translated error message to ui.Err if the error satisfies TranslatableError, otherwise it outputs the original error message to ui.Err. It also outputs "FAILED" in bold red to ui.Out.
func (*UI) DisplayHeader ¶
DisplayHeader translates the header, bolds and adds the default color to the header, and outputs the result to ui.Out.
func (*UI) DisplayInstancesTableForApp ¶
func (*UI) DisplayKeyValueTable ¶
DisplayKeyValueTable outputs a matrix of strings as a table to UI.Out. Prefix will be prepended to each row and padding adds the specified number of spaces between columns. The final columns may wrap to multiple lines but will still be confined to the last column. Wrapping will occur on word boundaries.
func (*UI) DisplayKeyValueTableForApp ¶
func (*UI) DisplayLogMessage ¶
func (ui *UI) DisplayLogMessage(message LogMessage, displayHeader bool)
DisplayLogMessage formats and outputs a given log message.
func (*UI) DisplayNewline ¶
func (ui *UI) DisplayNewline()
DisplayNewline outputs a newline to UI.Out.
func (*UI) DisplayNonWrappingTable ¶
DisplayNonWrappingTable outputs a matrix of strings as a table to UI.Out. Prefix will be prepended to each row and padding adds the specified number of spaces between columns.
func (*UI) DisplayOK ¶
func (ui *UI) DisplayOK()
DisplayOK outputs a bold green translated "OK" to UI.Out.
func (*UI) DisplayTableWithHeader ¶
func (*UI) DisplayText ¶
DisplayText translates the template, substitutes in templateValues, and outputs the result to ui.Out. Only the first map in templateValues is used.
func (*UI) DisplayTextWithFlavor ¶
DisplayTextWithFlavor translates the template, bolds and adds cyan color to templateValues, substitutes templateValues into the template, and outputs the result to ui.Out. Only the first map in templateValues is used.
func (*UI) DisplayWarning ¶
DisplayWarning translates the warning, substitutes in templateValues, and outputs to ui.Err. Only the first map in templateValues is used.
func (*UI) DisplayWarnings ¶
DisplayWarnings translates the warnings and outputs to ui.Err.
func (*UI) RequestLoggerFileWriter ¶
func (ui *UI) RequestLoggerFileWriter(filePaths []string) *RequestLoggerFileWriter
RequestLoggerFileWriter returns a RequestLoggerFileWriter that cannot overwrite another RequestLoggerFileWriter.
func (*UI) RequestLoggerTerminalDisplay ¶
func (ui *UI) RequestLoggerTerminalDisplay() *RequestLoggerTerminalDisplay
RequestLoggerTerminalDisplay returns a RequestLoggerTerminalDisplay that cannot overwrite another RequestLoggerTerminalDisplay or the current display.
func (*UI) TranslateText ¶
TranslateText passes the template through an internationalization function to translate it to a pre-configured language, and returns the template with templateValues substituted in. Only the first map in templateValues is used.