all repos — mx @ 7726cb04d27c4a65ddf8e62ed0f8431b47bdff7b

work in progress MUA

commands/commands.go (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
package commands

type Command interface {
	Aliases() []string
	Execute(cmd string) (interface{}, error)
}

var Commands = make(map[string]Command)

func Register(cmd Command) {
	for _, alias := range cmd.Aliases() {
		Commands[alias] = cmd
	}
}

func ProcessCommands(cmd string) {
	for k, v := range Commands {
		if cmd == k {
			v.Execute(cmd)
		}
	}
}