This commit is contained in:
19
internal/config/commands.go
Normal file
19
internal/config/commands.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package config
|
||||
|
||||
import "errors"
|
||||
|
||||
type Commands struct {
|
||||
Commands map[string]func(*State, Command) error
|
||||
}
|
||||
|
||||
func (c *Commands) Register(name string, f func(*State, Command) error) {
|
||||
c.Commands[name] = f
|
||||
}
|
||||
|
||||
func (c *Commands) Run(s *State, cmd Command) error {
|
||||
f, ok := c.Commands[cmd.Name]
|
||||
if !ok {
|
||||
return errors.New("unknown command: " + cmd.Name)
|
||||
}
|
||||
return f(s, cmd)
|
||||
}
|
||||
Reference in New Issue
Block a user