aboutsummaryrefslogtreecommitdiffstats
path: root/commands/commands.go
blob: 71dabe4cf0e5e760b3fc25a40b302730260f1f17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package commands

import (
	"errors"

	"git.sr.ht/~sircmpwn/aerc2/widgets"
)

type AercCommand func(aerc *widgets.Aerc, cmd string) error

var (
	commands map[string]AercCommand
)

func init() {
	commands = make(map[string]AercCommand)
}

func Register(name string, cmd AercCommand) {
	commands[name] = cmd
}

func ExecuteCommand(aerc *widgets.Aerc, cmd string) error {
	if fn, ok := commands[cmd]; ok {
		return fn(aerc, cmd)
	}
	return errors.New("Unknown command " + cmd)
}