Chakib Ben Ziane
03d30e6704
- inspired from golang database package and caddyserver modules - Migrating from class style to interfaces - FIX: browser provisioning is broken, config is not ready when the browser module is registered.
32 lines
650 B
Go
32 lines
650 B
Go
package cmd
|
|
|
|
import (
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// map cmd Name to *cli.Command
|
|
type modCmds map[string]*cli.Command
|
|
|
|
var (
|
|
// Map browser module IDs to their modCmds map
|
|
modCommands = map[string]modCmds{}
|
|
)
|
|
|
|
// TODO: use same logic with browser mod registering
|
|
func RegisterModCommand(modId string, cmd *cli.Command) {
|
|
if cmd == nil {
|
|
log.Panicf("cannot register nil cmd for <%s>", modId)
|
|
}
|
|
|
|
if _, ok := modCommands[modId]; !ok {
|
|
modCommands[modId] = make(modCmds)
|
|
}
|
|
modCommands[modId][cmd.Name] = cmd
|
|
}
|
|
|
|
// return list of registered commands for browser module
|
|
func ModCommands(modId string) modCmds {
|
|
|
|
return modCommands[modId]
|
|
}
|