command

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2018 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SINGLE_REGISTRATION = iota
	MULTI_REGISTRATION
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// Command name
	Name string

	// Command aliases
	Aliases []string

	// Single line general usage description
	Usage string

	// Single line specific usage example
	Eg string

	// Single line summarizing this command
	Short string

	// Multiple line description of this command
	Long string

	// Plugin command type flag
	IsPlugin bool

	// Function invoked by the command router
	Run func(ctx *env.Context)
}

func (*Command) Runnable

func (t *Command) Runnable() bool

Runnable indicates whether this command can be invoked. Non runnable commands are information only commands.

type HandlerFunc

type HandlerFunc func(*env.Context)

type Router

type Router struct {
	// contains filtered or unexported fields
}
var CmdRouter *Router = NewRouter(use)

func NewRouter

func NewRouter(handler HandlerFunc) *Router

Returns a newly configured, ready-to-use command router. Provide a non-nil handler function with the following signature

func(*cmd.Context)

and the router will use function as the default that will be called when no registerd commands match the command requested in the user specified command string. A default handler is most often used when creating a top-level command router in which arbitrary tokens are used to activate a particular ruby runtime.

If the default handler function is nil, the function will never be called.

func (*Router) Commands

func (r *Router) Commands() *map[string]*Command

Commands returns the, possibly empty, map of currently registered commands indexed by their canonical names.

func (*Router) Dispatch

func (r *Router) Dispatch(ctx *env.Context, cmd string)

Dispatch calls the `Run` method of a previously registerd command instance corresponding to the user specified command string, passing a context as the only arg. If the command string is not a recognized command, and the command router instance has been created with a non-nil default handler, the default handler will be invoked with a context as the only arg.

func (*Router) Handle

func (r *Router) Handle(cmds []string, handler *Command)

Handle registers a command to a set of user CLI command alias strings. The registered command's `Run` method is executed whenever a user specifies one of the command aliases.

func (*Router) Handler

func (r *Router) Handler(cmd string) (handler *Command, err error)

Handler returns the, possibly nil, command registered with the given command string alias.

func (*Router) Handlers

func (r *Router) Handlers() *map[string]*Command

Handlers returns the, possibly empty, map of currently registered commands indexed by their aliases.

Jump to

Keyboard shortcuts

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