Documentation
¶
Overview ¶
Package output prints command results and errors as text or JSON.
Results go to stdout. In JSON mode errors also go to stdout, so a caller always reads exactly one JSON document there. In text mode errors go to stderr.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
Code ExitCode
Message string
Hint string
Err error
// Silent errors only set the exit code. The command has already printed
// its result, and printing an error too would break the one-JSON-document rule.
Silent bool
}
Error is an error with an exit code and an optional hint that tells the user how to fix it.
type ExitCode ¶
type ExitCode int
ExitCode is the process exit code. The values are part of the public CLI contract.
const ( ExitOK ExitCode = 0 ExitError ExitCode = 1 // generic error ExitUsage ExitCode = 2 // bad usage or input ExitPrerequisite ExitCode = 3 // prerequisite missing ExitUnhealthy ExitCode = 4 // service not healthy ExitRemote ExitCode = 5 // remote API error ExitAuth ExitCode = 6 // authentication failed )
type ExitCodeInfo ¶ added in v0.3.1
type ExitCodeInfo struct {
Code int `json:"code"`
Name string `json:"name"`
Meaning string `json:"meaning"`
}
ExitCodeInfo describes one exit code.
func ExitCodes ¶ added in v0.3.1
func ExitCodes() []ExitCodeInfo
ExitCodes lists every exit code, in order.
type Format ¶
type Format string
Format is an output format.
func ParseFormat ¶
ParseFormat validates s as an output format.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer writes results and errors in one format.
func NewPrinter ¶
NewPrinter returns a printer that writes results to out and text errors to errw.