Documentation
¶
Index ¶
- func DirectStreams() (io.Writer, io.Writer, error)
- func Fatal(errorMsg string, exitCode ExitCode)
- func FatalError(err error, exitCode ExitCode)
- func FatalResult(res ErrorResult, exitCode ExitCode)
- func NewBufferedStreams() (io.Writer, io.Writer, func() *OutputStreamsResult)
- func OutputStreams() (io.Writer, io.Writer, func() *OutputStreamsResult)
- func Print(v string)
- func PrintResult(res Result)
- func Printf(format string, v ...interface{})
- func SetErr(err io.Writer)
- func SetFormat(f OutputFormat)
- func SetOut(out io.Writer)
- func Warnf(msg string, args ...interface{})
- 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 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 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 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 SetFormat ¶
func SetFormat(f OutputFormat)
SetFormat can be used to change the output format at runtime
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 // 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 )
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 )
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