91 lines
1.5 KiB
Go
91 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"git.sr.ht/~cco/go-scopes/lib"
|
|
)
|
|
|
|
type Cfg struct {
|
|
*Base
|
|
ConfigFormat string
|
|
}
|
|
|
|
func Start(ctx lib.Context) {
|
|
}
|
|
|
|
// definitions
|
|
|
|
type Base struct {
|
|
name string
|
|
starter lib.StartProc
|
|
step lib.StepProc
|
|
msgHandler lib.MessageHandler
|
|
actions []lib.ActionConfig
|
|
children []lib.Config
|
|
}
|
|
|
|
// lib.Config implementation
|
|
|
|
func (cfg *Base) Name() string {
|
|
return cfg.name
|
|
}
|
|
|
|
func (cfg *Base) Starter() lib.StartProc {
|
|
return cfg.starter
|
|
}
|
|
|
|
func (cfg *Base) Step() lib.StepProc {
|
|
return cfg.step
|
|
}
|
|
|
|
func (cfg *Base) MessageHandler() lib.MessageHandler {
|
|
return cfg.msgHandler
|
|
}
|
|
|
|
func (cfg *Base) Actions() []lib.ActionConfig {
|
|
return cfg.actions
|
|
}
|
|
|
|
func (cfg *Base) Children() []lib.Config {
|
|
return cfg.children
|
|
}
|
|
|
|
func (cfg *Base) Add(child lib.Config) {
|
|
cfg.children = append(cfg.children, child)
|
|
}
|
|
|
|
// implementation-specific methods and functions
|
|
|
|
func (cfg *Base) WithStep(step lib.StepProc) *Base {
|
|
cfg.step = step
|
|
return cfg
|
|
}
|
|
|
|
func (cfg *Base) WithMessageHandler(hdlr lib.MessageHandler) *Base {
|
|
cfg.msgHandler = hdlr
|
|
return cfg
|
|
}
|
|
|
|
func MakeBase(name string, starter lib.StartProc) *Base {
|
|
return &Base{
|
|
name: name,
|
|
starter: starter,
|
|
actions: nil,
|
|
}
|
|
}
|
|
|
|
// overridable settings
|
|
|
|
type Settings map[string]string
|
|
|
|
func (s Settings) Use(value, key string) string {
|
|
if v, ok := os.LookupEnv("SCOPES_" + strings.ToUpper(key)); ok {
|
|
return v
|
|
}
|
|
if v, ok := s[key]; ok {
|
|
return v
|
|
}
|
|
return value
|
|
}
|