package commands import ( "fmt" ) type Command interface { Aliases() []string Execute(cmd string) 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 { err := v.Execute(cmd) if err != nil { fmt.Errorf("error: executing %s failed: %+v\n", cmd, err) } } } }