forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commander.go
33 lines (27 loc) · 984 Bytes
/
commander.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package gobot
type commander struct {
commands map[string]func(map[string]interface{}) interface{}
}
type Commander interface {
Command(string) (command func(map[string]interface{}) interface{})
Commands() (commands map[string]func(map[string]interface{}) interface{})
AddCommand(name string, command func(map[string]interface{}) interface{})
}
func NewCommander() Commander {
return &commander{
commands: make(map[string]func(map[string]interface{}) interface{}),
}
}
// Command retrieves a command by name
func (c *commander) Command(name string) (command func(map[string]interface{}) interface{}) {
command, _ = c.commands[name]
return
}
// Commands returns a map of driver commands
func (c *commander) Commands() map[string]func(map[string]interface{}) interface{} {
return c.commands
}
// AddCommand links specified command name to `f`
func (c *commander) AddCommand(name string, command func(map[string]interface{}) interface{}) {
c.commands[name] = command
}