Documentation ¶
Index ¶
Constants ¶
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) }
type HandlerFunc ¶
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
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 ¶
Commands returns the, possibly empty, map of currently registered commands indexed by their canonical names.
func (*Router) Dispatch ¶
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 ¶
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.