Documentation ¶
Index ¶
- func Version() string
- type DefaultSession
- func (s *DefaultSession) Err() io.Writer
- func (s *DefaultSession) ExitOnErr(err error, msg string, code int)
- func (s *DefaultSession) ExitOnErrShort(err error, msg string, code int)
- func (s *DefaultSession) ExitOnErrsShort(errs []error, code int)
- func (s *DefaultSession) Exitf(code int, format string, a ...interface{})
- func (s *DefaultSession) In() io.Reader
- func (s *DefaultSession) OnSignal(sig os.Signal, f func(os.Signal)) (cancel func())
- func (s *DefaultSession) Out() io.Writer
- func (s *DefaultSession) SetErr(w io.Writer)
- func (s *DefaultSession) SetIn(r io.Reader)
- func (s *DefaultSession) SetOut(w io.Writer)
- type Input
- type Mixin
- type PostRun
- type PreRun
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DefaultSession ¶ added in v0.1.4
type DefaultSession struct {
// contains filtered or unexported fields
}
DefaultSession can be embedded in all mixins and sub-command handlers and provide a default implementation of the Session interface which uses os.Stdout, os.Stderr, and os.Stdin by default.
func (*DefaultSession) Err ¶ added in v0.1.4
func (s *DefaultSession) Err() io.Writer
func (*DefaultSession) ExitOnErr ¶ added in v0.1.4
func (s *DefaultSession) ExitOnErr(err error, msg string, code int)
func (*DefaultSession) ExitOnErrShort ¶ added in v0.1.4
func (s *DefaultSession) ExitOnErrShort(err error, msg string, code int)
func (*DefaultSession) ExitOnErrsShort ¶ added in v0.1.4
func (s *DefaultSession) ExitOnErrsShort(errs []error, code int)
func (*DefaultSession) Exitf ¶ added in v0.1.4
func (s *DefaultSession) Exitf(code int, format string, a ...interface{})
func (*DefaultSession) In ¶ added in v0.1.4
func (s *DefaultSession) In() io.Reader
func (*DefaultSession) OnSignal ¶ added in v0.1.4
func (s *DefaultSession) OnSignal(sig os.Signal, f func(os.Signal)) (cancel func())
func (*DefaultSession) Out ¶ added in v0.1.4
func (s *DefaultSession) Out() io.Writer
func (*DefaultSession) SetErr ¶ added in v0.1.4
func (s *DefaultSession) SetErr(w io.Writer)
func (*DefaultSession) SetIn ¶ added in v0.1.4
func (s *DefaultSession) SetIn(r io.Reader)
func (*DefaultSession) SetOut ¶ added in v0.1.4
func (s *DefaultSession) SetOut(w io.Writer)
type Input ¶ added in v0.1.4
type Input struct { // Args holds all unbound arguments except for the first "--" if present. Args []string // ArgsBeforeDash holds the subset of Args located before the first "--" if present, // or the same elements as Args if absent. ArgsBeforeDash []string // ArgsAfterDash holds the subset of Args located after the first "--" if present. ArgsAfterDash []string }
Input defines the framework-agnostic user input passed to handler's Run methods.
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 Session ¶ added in v0.1.4
type Session 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) // ExitOnError exits the program if the error is non-nil and prints the error in full format (%+v). ExitOnErr(err error, msg string, code int) // ExitOnErrorShort exits the program if the error is non-nil and prints the error's string value. ExitOnErrShort(err error, msg string, code int) // ExitOnErrsShort exits the program if the slice is non-empty and prints each error's string value. ExitOnErrsShort(errs []error, code int) // Exitf exits the program with a formatted message. Exitf(code int, format string, a ...interface{}) }
Session defines CLI handler behaviors which are useful to replace with test doubles.
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