generated from templates/go-generic
Dan Anglin
7783c10504
- Moved the state implementation to internal/state. - Moved the executors to internal/executors.
31 lines
537 B
Go
31 lines
537 B
Go
package executors
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"codeflow.dananglin.me.uk/apollo/gator/internal/state"
|
|
)
|
|
|
|
type ExecutorMap struct {
|
|
Map map[string]ExecutorFunc
|
|
}
|
|
|
|
type ExecutorFunc func(*state.State, Executor) error
|
|
|
|
type Executor struct {
|
|
Name string
|
|
Args []string
|
|
}
|
|
|
|
func (e *ExecutorMap) Register(name string, f ExecutorFunc) {
|
|
e.Map[name] = f
|
|
}
|
|
|
|
func (e *ExecutorMap) Run(s *state.State, exe Executor) error {
|
|
runFunc, ok := e.Map[exe.Name]
|
|
if !ok {
|
|
return fmt.Errorf("unrecognised command: %s", exe.Name)
|
|
}
|
|
|
|
return runFunc(s, exe)
|
|
}
|