forked from adamlaska/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistry.go
More file actions
44 lines (37 loc) · 822 Bytes
/
registry.go
File metadata and controls
44 lines (37 loc) · 822 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cmd
import (
"fmt"
"sort"
"sync"
)
var registry struct {
sync.Mutex
commands map[string]func()
}
// Register a boulder subcommand to be run when the binary name matches `name`.
func RegisterCommand(name string, f func()) {
registry.Lock()
defer registry.Unlock()
if registry.commands == nil {
registry.commands = make(map[string]func())
}
if registry.commands[name] != nil {
panic(fmt.Sprintf("command %q was registered twice", name))
}
registry.commands[name] = f
}
func LookupCommand(name string) func() {
registry.Lock()
defer registry.Unlock()
return registry.commands[name]
}
func AvailableCommands() []string {
registry.Lock()
defer registry.Unlock()
var avail []string
for name := range registry.commands {
avail = append(avail, name)
}
sort.Strings(avail)
return avail
}