Documentation ¶
Index ¶
- type IO
- func (h *IO) Err() io.Writer
- func (h *IO) Exit(code int, a ...interface{})
- func (h *IO) ExitOnErr(err error, msg string, code int)
- func (h *IO) ExitOnErrShort(err error, msg string, code int)
- func (h *IO) ExitOnErrsShort(errs []error, code int)
- func (h *IO) Exitf(code int, format string, a ...interface{})
- func (h *IO) In() io.Reader
- func (h *IO) OnSignal(s os.Signal, f func(os.Signal)) (cancel func())
- func (h *IO) Out() io.Writer
- func (h *IO) SetErr(w io.Writer)
- func (h *IO) SetIn(r io.Reader)
- func (h *IO) SetOut(w io.Writer)
- type Mixin
- type PostRun
- type PreRun
- type Responder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IO ¶
type IO struct {
// contains filtered or unexported fields
}
IO can be embedded in all mixins and sub-command handlers and provide a default implementation of the Responder interface.
func (*IO) ExitOnErrsShort ¶
type PostRun ¶
PostRun is optionally implemented by handlers/mixins to perform tasks after Handler.Run finishes.
type PreRun ¶
PreRun is optionally implemented by handlers/mixins to perform tasks after flags are parsed but before Handler.Run.
If it returns an error, Handler.Run and Handler.PostRun do not execute.
type Responder ¶
type Responder interface { // Err returns the standard error destination. Err() io.Writer // In returns the standard input source. In() io.Reader // OnSignal starts a goroutine which runs the provided function every time the signal // is received. It returns a function to end the goroutine. OnSignal(s os.Signal, do func(os.Signal)) (cancel func()) // Out returns the standard output destination. Out() io.Writer // SetErr assigns the standard error destination. SetErr(io.Writer) // SetIn assigns the standard input source. SetIn(io.Reader) // SetOut assigns the standard error destination. SetOut(io.Writer) }
Responder defines the common response behavior expected from each sub-command implementation.
Behaviors related to terminal I/O are based on the interface approach in docker's CLI:
https://github.com/docker/cli/blob/f1b116179f2a95d0ea45780dfb8be51c2825b9c0/cli/command/cli.go https://www.apache.org/licenses/LICENSE-2.0.html
Specifically, Out and Err methods are intended to improve testability by expecting that terminal messages can be captured for assertions about their content (as they are in docker's own CLI tests).