Version: v0.2.0 Latest Latest

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

Go to latest
Published: Jan 6, 2016 License: MPL-2.0 Imports: 8 Imported by: 39




This section is empty.


View Source
var ErrHelp = errors.New("help")

ErrHelp can be returned by Execute functions to force the action to show help for a given command.


This section is empty.


type Action

type Action interface {
	// Execute is the callback that'll be called to execute this action.
	Execute(ctx Context) error

	// Help is the help text for this action.
	Help() string

	// Synopsis is the text that will be shown as a short sentence
	// about what this action does.
	Synopsis() string

Action defines an action that is available for the router.

type Context

type Context interface {
	RouteName() string
	RouteArgs() []string
	UI() ui.Ui

Context is passed to the router and used to select which action is executed. This same value will also be passed down into the selected Action's Execute function. This is so that actions typecast the context to access implementation-specific data.

type Router

type Router struct {
	Actions map[string]Action

Router is a helper to route subcommands to specific callbacks.

Actions are available on a lot of commands such as dev, deploy, etc. and this can be used to add custom actions.

func (*Router) Route

func (r *Router) Route(ctx Context) error

Route will route the given Context to the proper Action.

type SimpleAction

type SimpleAction struct {
	ExecuteFunc  func(Context) error
	HelpText     string
	SynopsisText string

func (*SimpleAction) Execute

func (sa *SimpleAction) Execute(ctx Context) error

func (*SimpleAction) Help

func (sa *SimpleAction) Help() string

func (*SimpleAction) Synopsis

func (sa *SimpleAction) Synopsis() string

Jump to

Keyboard shortcuts

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