feedback
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package feedback provides an uniform API that can be used toprint 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 HasConsole() bool
- func InputUserField(prompt string, secret bool) (string, error)
- func InteractiveStreams() (io.Reader, io.Writer, error)
- func IsCI() bool
- func IsInteractive() bool
- 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 RestoreModeStdin()
- func SetErr(err io.Writer)
- func SetFormat(f OutputFormat)
- func SetOut(out io.Writer)
- func SetRawModeStdin() error
- func TaskProgress() rpc.TaskProgressCB
- func WarnAboutDeprecatedFiles(s *rpc.Sketch)
- 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¶
funcDirectStreams¶
DirectStreams returns the underlying io.Writer to directly stream tostdout and stderr.If the selected output format is not Text, the function will error.
Using the streams returned by this function allows direct control ofthe output and the PrintResult function must not be used anymore
funcExitWhenParentProcessEnds¶
func ExitWhenParentProcessEnds()
ExitWhenParentProcessEnds waits until the controlling parent process ends and then exitsthe current process. This is useful to terminate the current process when it is daemonizedand the controlling parent process is terminated to avoid leaving zombie processes.It is recommended to call this function as a goroutine.
funcFatalError¶
FatalError outputs the error and exits with status exitCode.
funcFatalResult¶
func FatalResult(resErrorResult, exitCodeExitCode)
FatalResult outputs the result and exits with status exitCode.
funcHasConsole¶added inv1.0.0
func HasConsole()bool
HasConsole returns true if the CLI outputs to a terminal/console
funcInputUserField¶
InputUserField prompts the user to input the provided user field.
funcInteractiveStreams¶
InteractiveStreams returns the underlying io.Reader and io.Writer to directly stream tostdin and stdout. It errors if the selected output format is not Text or the terminal isnot interactive.
funcIsCI¶added inv1.0.0
func IsCI()bool
IsCI returns true if running on CI environments.(based onhttps://github.com/watson/ci-info/blob/HEAD/index.js)
funcIsInteractive¶added inv1.0.0
func IsInteractive()bool
IsInteractive returns true if the CLI is interactive (it can receive inputs from terminal/console)
funcNewBufferedStreams¶
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 commandexecution is completed. The io.Writes will not affect other feedback streams.
This function returns also a callback that must be called when thecommand execution is completed, it will return an *OutputStreamsResultobject that can be used as a Result or to retrieve the accumulated outputto embed it in another object.
funcNewDownloadProgressBarCB¶
func NewDownloadProgressBarCB() func(*rpc.DownloadProgress)
NewDownloadProgressBarCB creates a progress bar callback that outputs a progressbar on the terminal
funcNewTaskProgressCB¶
func NewTaskProgressCB() func(curr *rpc.TaskProgress)
NewTaskProgressCB returns a commands.TaskProgressCB progress listenerthat outputs to terminal
funcOutputStreams¶
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 commandexecution is completed, so they are not suitable for printing an unboundedstream like a debug logger or an event watcher (use DirectStreams forthat purpose).
If the output format is Text the output will be directly streamed to theunderlying stdio streams in real time.
This function returns also a callback that must be called when thecommand execution is completed, it will return an *OutputStreamsResultobject that can be used as a Result or to retrieve the accumulated outputto embed it in another object.
funcPrint¶
func Print(vstring)
Print behaves like fmt.Print but writes on the out writer and adds a newline.
funcPrintResult¶
func PrintResult(resResult)
PrintResult is a convenient wrapper to provide feedback for complex data,where the contents can't be just serialized to JSON but requires morestructure.
funcPrintf¶
func Printf(formatstring, v ...interface{})
Printf behaves like fmt.Printf but writes on the out writer and adds a newline.
funcProgressBar¶
func ProgressBar()rpc.DownloadProgressCB
ProgressBar returns a DownloadProgressCB that prints a progress bar.
funcRestoreModeStdin¶
func RestoreModeStdin()
RestoreModeStdin restore the terminal settings to the normal non-RAW state. Thisfunction must be called after SetRawModeStdin to not leave the terminal in anundefined state.
funcSetFormat¶
func SetFormat(fOutputFormat)
SetFormat can be used to change the output format at runtime
funcSetRawModeStdin¶
func SetRawModeStdin()error
SetRawModeStdin sets the stdin stream in RAW mode (no buffering, echo disabled,no terminal escape codes nor signals interpreted)
funcTaskProgress¶
func TaskProgress()rpc.TaskProgressCB
TaskProgress returns a TaskProgressCB that prints the task progress.
funcWarnAboutDeprecatedFiles¶added inv1.0.0
WarnAboutDeprecatedFiles warns the user that a type of sketch files are deprecated
Types¶
typeErrorResult¶
ErrorResult is a result embedding also an error. In case of textual outputthe error will be printed on stderr.
typeExitCode¶
type ExitCodeint
ExitCode to be used for Fatal.
const (// Success (0 is the no-error return code in Unix)SuccessExitCode =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// ErrFailedToListenToTCPPort is returned if the CLI failed to open a TCP port// to listen for incoming connections (8)ErrFailedToListenToTCPPort// ErrBadTCPPortArgument is returned if the TCP port argument is not valid (9)ErrBadTCPPortArgument// ErrInitializingInventory is returned when the inventory cannot be initialized,// usually depends on a wrong configuration of the data dir (10)ErrInitializingInventory// ErrMissingProgrammer is returned when the programmer argument is missing (11)ErrMissingProgrammer)
typeOutputFormat¶
type OutputFormatint
OutputFormat is an output format
const (// Text is the plain text format, suitable for interactive terminalsTextOutputFormat =iota// JSON formatJSON// MinifiedJSON formatMinifiedJSON)
funcParseOutputFormat¶
func ParseOutputFormat(instring) (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 (fOutputFormat) String()string
typeOutputStreamsResult¶
OutputStreamsResult contains the accumulated stdout and stderr outputwhen 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