commands/commands.go (view raw)
1package commands
2
3import (
4 "fmt"
5)
6
7type Command interface {
8 Aliases() []string
9 Execute(cmd string) error
10}
11
12var Commands = make(map[string]Command)
13
14func Register(cmd Command) {
15 for _, alias := range cmd.Aliases() {
16 Commands[alias] = cmd
17 }
18}
19
20func ProcessCommands(cmd string) {
21 for k, v := range Commands {
22 if cmd == k {
23 err := v.Execute(cmd)
24 if err != nil {
25 fmt.Errorf("error: executing %s failed: %+v\n", cmd, err)
26 }
27 }
28 }
29}