rename/reorganize access to overridable settings

This commit is contained in:
Helmut Merz 2023-06-02 10:13:27 +02:00
parent f896adfb8c
commit ca37aead92
4 changed files with 8 additions and 8 deletions

View file

@ -61,12 +61,12 @@ func Setup(cfg Config) Config {
type Settings map[string]string
func (s Settings) Get(key, def 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 def
return value
}

View file

@ -6,18 +6,19 @@ import (
)
func Config() config.Config {
ovr := Overrides().Get
ovr := Overrides().Use
b := config.MakeBase
cfg := scopes.Cfg{
Base: b("dummy", scopes.Start),
Home: ovr(HOME, "."),
Home: ovr(".", HOME),
AppType: "standard",
}
cfg.Add(config.Cfg{b("config", config.Start), "etc"})
return &cfg
}
// collect here the names of fields that may be overridden via
// explicit Override() or SCOPES_* environment settings.
const (
NAME = "name"
HOME = "home"
)

View file

@ -4,7 +4,6 @@ import "git.sr.ht/~cco/go-scopes/config"
func Overrides() config.Settings {
return config.Settings{
NAME: "overridden",
HOME: "/home/scopes/app",
}
}

View file

@ -6,11 +6,11 @@ import (
)
func Config() config.Config {
ovr := Overrides().Get
ovr := Overrides().Use
b := config.MakeBase
cfg := scopes.Cfg{
Base: b("dummy", scopes.Start),
Home: ovr(HOME, "."),
Home: ovr(".", HOME),
AppType: "standard",
}
cfg.Add(config.Cfg{b("config", config.Start), "etc"})