handler

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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) Err

func (h *IO) Err() io.Writer

func (*IO) Exit

func (h *IO) Exit(code int, a ...interface{})

func (*IO) ExitOnErr

func (h *IO) ExitOnErr(err error, msg string, code int)

func (*IO) ExitOnErrShort

func (h *IO) ExitOnErrShort(err error, msg string, code int)

func (*IO) ExitOnErrsShort

func (h *IO) ExitOnErrsShort(errs []error, code int)

func (*IO) Exitf

func (h *IO) Exitf(code int, format string, a ...interface{})

func (*IO) In

func (h *IO) In() io.Reader

func (*IO) OnSignal

func (h *IO) OnSignal(s os.Signal, f func(os.Signal)) (cancel func())

func (*IO) Out

func (h *IO) Out() io.Writer

func (*IO) SetErr

func (h *IO) SetErr(w io.Writer)

func (*IO) SetIn

func (h *IO) SetIn(r io.Reader)

func (*IO) SetOut

func (h *IO) SetOut(w io.Writer)

type Mixin

type Mixin interface {
	// BindCobraFlags gives each mixin the opportunity to define its own flags.
	BindCobraFlags(cmd *cobra.Command) (requiredFlags []string)

	// Name should identify the mixin for use in error/log messages.
	//
	// Ideally it is short, e.g. like a package name.
	Name() string
}

type PostRun

type PostRun interface {
	PostRun(ctx context.Context)
}

PostRun is optionally implemented by handlers/mixins to perform tasks after Handler.Run finishes.

type PreRun

type PreRun interface {
	PreRun(ctx context.Context, args []string) error
}

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 approached used in docker itself (e.g. ClI interface): https://github.com/docker/cli/blob/f1b116179f2a95d0ea45780dfb8be51c2825b9c0/cli/command/cli.go. 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).

Directories

Path Synopsis
mixin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL