This commit is contained in:
2025-03-11 08:36:29 +02:00
parent d1163ec629
commit f23f3fbf53
6 changed files with 81 additions and 23 deletions

View 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)
}