Documentation
¶
Index ¶
- type Base
- func (base *Base) CommandExists(command string) bool
- func (base *Base) Get(key string) interface{}
- func (base *Base) GetCommand(command string) (Command, bool)
- func (base *Base) HandleCommand(input string, store Store) (bool, error)
- func (base *Base) Register(command Command) error
- func (base *Base) Set(key string, value interface{})
- type Command
- type Context
- type HandlerFunc
- type MiddlewareFunc
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
CommandSymbol string
Commands map[string]Command
UnknownCommandMessage string
Store
}
Base is our command base. It keeps track of all commands and their handlers
func New ¶
New is the function for creating a new command base. Please use this function instead of creating an instance of Base yourself!
If you really must create a Base yourself, then make sure that CommandSymbol and UnknownCommandMessage are set, and that you initialize the Commands map yourself or else you will run into some issues!
func (*Base) CommandExists ¶
CommandExists checks if a command is registered. It returns true if it is, false if it isn't. CommandExists compares the Name fields of commands.
func (*Base) GetCommand ¶
GetCommand retrieves a Command by it's name field from the command base.
GetCommand returns a Command and a boolean. This boolean is true if a command was found, and false if a command could not be found with the provided name.
func (*Base) HandleCommand ¶
HandleCommand is called to run what is assumed to be a command.
HandlerCommand returns a boolean and an error. The boolean is true if the input provided was structed as a proper command meaning that it was a string whose first character is equal to this base's CommandSymbol. If it was not a structured command the bool will be false and the returned error will be nil. In this case, you should assume the user was not trying to execute a command.
If the user entered a properly structured command, but it was either an unknown command or if the input failed validation then the bool will be false and error will be set to an error.
If the command was fully executed successfully, the bool will be true and error will be nil.
type Command ¶
type Command struct {
Name string
Usage string
Handler HandlerFunc
// contains filtered or unexported fields
}
Command is a struct which holds the data required for a command
func (*Command) Use ¶ added in v0.1.2
func (cmd *Command) Use(middleware ...MiddlewareFunc)
Use adds middleware to the middleware chain
type Context ¶
Context holds context data for use by command handlers
type HandlerFunc ¶ added in v0.1.2
HandlerFunc is a type representation of a command handling function. Handler functions should return true if they were executed successfully, and false if they were cancelled.
type MiddlewareFunc ¶ added in v0.1.2
type MiddlewareFunc func(HandlerFunc) HandlerFunc
MiddlewareFunc represents a chainable middleware function