go-scopes/config/config.go

67 lines
1,012 B
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
actions []lib.ActionConfig
children []lib.Config
}
func (cfg *Base) Name() string {
return cfg.name
}
func (cfg *Base) Starter() lib.StartProc {
return cfg.starter
}
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)
}
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
}