router

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2015 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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