Documentation ¶
Overview ¶
Package feedback provides an uniform API that can be used to print feedback to the users in different formats.
Index ¶
- func DirectStreams() (io.Writer, io.Writer, error)
- func ExitWhenParentProcessEnds()
- func Fatal(errorMsg string, exitCode ExitCode)
- func FatalError(err error, exitCode ExitCode)
- func FatalResult(res ErrorResult, exitCode ExitCode)
- func InputUserField(prompt string, secret bool) (string, error)
- func InteractiveStreams() (io.Reader, io.Writer, error)
- func NewBufferedStreams() (io.Writer, io.Writer, func() *OutputStreamsResult)
- func NewCommand() *cobra.Command
- func NewDownloadProgressBarCB() func(*rpc.DownloadProgress)
- func NewTaskProgressCB() func(curr *rpc.TaskProgress)
- func OutputStreams() (io.Writer, io.Writer, func() *OutputStreamsResult)
- func Print(v string)
- func PrintResult(res Result)
- func Printf(format string, v ...interface{})
- func ProgressBar() rpc.DownloadProgressCB
- func SetErr(err io.Writer)
- func SetFormat(f OutputFormat)
- func SetOut(out io.Writer)
- func TaskProgress() rpc.TaskProgressCB
- func Warning(msg string)
- type ErrorResult
- type ExitCode
- type OutputFormat
- type OutputStreamsResult
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DirectStreams ¶
DirectStreams returns the underlying io.Writer to directly stream to stdout and stderr. If the selected output format is not Text, the function will error.
Using the streams returned by this function allows direct control of the output and the PrintResult function must not be used anymore
func ExitWhenParentProcessEnds ¶
func ExitWhenParentProcessEnds()
ExitWhenParentProcessEnds waits until the controlling parent process ends and then exits the current process. This is useful to terminate the current process when it is daemonized and the controlling parent process is terminated to avoid leaving zombie processes. It is recommended to call this function as a goroutine.
func FatalError ¶
FatalError outputs the error and exits with status exitCode.
func FatalResult ¶
func FatalResult(res ErrorResult, exitCode ExitCode)
FatalResult outputs the result and exits with status exitCode.
func InputUserField ¶
InputUserField prompts the user to input the provided user field.
func InteractiveStreams ¶
InteractiveStreams returns the underlying io.Reader and io.Writer to directly stream to stdin and stdout. It errors if the selected output format is not Text or the terminal is not interactive.
func NewBufferedStreams ¶
func NewBufferedStreams() (io.Writer, io.Writer, func() *OutputStreamsResult)
NewBufferedStreams returns a pair of io.Writer to buffer the command output. The returned writers will accumulate the output until the command execution is completed. The io.Writes will not affect other feedback streams.
This function returns also a callback that must be called when the command execution is completed, it will return an *OutputStreamsResult object that can be used as a Result or to retrieve the accumulated output to embed it in another object.
func NewDownloadProgressBarCB ¶
func NewDownloadProgressBarCB() func(*rpc.DownloadProgress)
NewDownloadProgressBarCB creates a progress bar callback that outputs a progress bar on the terminal
func NewTaskProgressCB ¶
func NewTaskProgressCB() func(curr *rpc.TaskProgress)
NewTaskProgressCB returns a commands.TaskProgressCB progress listener that outputs to terminal
func OutputStreams ¶
func OutputStreams() (io.Writer, io.Writer, func() *OutputStreamsResult)
OutputStreams returns a pair of io.Writer to write the command output. The returned writers will accumulate the output until the command execution is completed, so they are not suitable for printing an unbounded stream like a debug logger or an event watcher (use DirectStreams for that purpose).
If the output format is Text the output will be directly streamed to the underlying stdio streams in real time.
This function returns also a callback that must be called when the command execution is completed, it will return an *OutputStreamsResult object that can be used as a Result or to retrieve the accumulated output to embed it in another object.
func Print ¶
func Print(v string)
Print behaves like fmt.Print but writes on the out writer and adds a newline.
func PrintResult ¶
func PrintResult(res Result)
PrintResult is a convenient wrapper to provide feedback for complex data, where the contents can't be just serialized to JSON but requires more structure.
func Printf ¶
func Printf(format string, v ...interface{})
Printf behaves like fmt.Printf but writes on the out writer and adds a newline.
func ProgressBar ¶
func ProgressBar() rpc.DownloadProgressCB
ProgressBar returns a DownloadProgressCB that prints a progress bar.
func SetFormat ¶
func SetFormat(f OutputFormat)
SetFormat can be used to change the output format at runtime
func TaskProgress ¶
func TaskProgress() rpc.TaskProgressCB
TaskProgress returns a TaskProgressCB that prints the task progress.
Types ¶
type ErrorResult ¶
ErrorResult is a result embedding also an error. In case of textual output the error will be printed on stderr.
type ExitCode ¶
type ExitCode int
ExitCode to be used for Fatal.
const ( // Success (0 is the no-error return code in Unix) Success ExitCode = iota // ErrGeneric Generic error (1 is the reserved "catchall" code in Unix) ErrGeneric // ErrNoConfigFile is returned when the config file is not found (3) ErrNoConfigFile // ErrNetwork is returned when a network error occurs (5) ErrNetwork // ErrCoreConfig represents an error in the cli core config, for example some basic // files shipped with the installation are missing, or cannot create or get basic // directories vital for the CLI to work. (6) ErrCoreConfig // ErrBadArgument is returned when the arguments are not valid (7) ErrBadArgument )
type OutputFormat ¶
type OutputFormat int
OutputFormat is an output format
const ( // Text is the plain text format, suitable for interactive terminals Text OutputFormat = iota // JSON format JSON // MinifiedJSON format MinifiedJSON // YAML format YAML )
func ParseOutputFormat ¶
func ParseOutputFormat(in string) (OutputFormat, bool)
ParseOutputFormat parses a string and returns the corresponding OutputFormat. The boolean returned is true if the string was a valid OutputFormat.
func (OutputFormat) String ¶
func (f OutputFormat) String() string
type OutputStreamsResult ¶
OutputStreamsResult contains the accumulated stdout and stderr output when the selected output format is not Text.
func (*OutputStreamsResult) Data ¶
func (r *OutputStreamsResult) Data() interface{}
Data returns the result object itself, it is used to implement the Result interface.
func (*OutputStreamsResult) Empty ¶
func (r *OutputStreamsResult) Empty() bool
Empty returns true if both Stdout and Stderr are empty.
func (*OutputStreamsResult) String ¶
func (r *OutputStreamsResult) String() string