From c3c71345db9086392cd9b7529c7f5287009c226e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 24 Sep 2025 23:21:43 +0300 Subject: Add runtime config store and reload command --- internal/appconfig/config.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'internal/appconfig/config.go') diff --git a/internal/appconfig/config.go b/internal/appconfig/config.go index 9119688..adf9b75 100644 --- a/internal/appconfig/config.go +++ b/internal/appconfig/config.go @@ -162,7 +162,16 @@ func newDefaultConfig() App { // Load reads configuration from a file and merges with defaults. // It respects the XDG Base Directory Specification. -func Load(logger *log.Logger) App { +func Load(logger *log.Logger) App { return LoadWithOptions(logger, LoadOptions{}) } + +// LoadOptions tune how configuration is loaded at runtime. +type LoadOptions struct { + // IgnoreEnv skips applying environment overrides when true. + IgnoreEnv bool +} + +// LoadWithOptions reads configuration and applies the requested loading options. +func LoadWithOptions(logger *log.Logger, opts LoadOptions) App { cfg := newDefaultConfig() if logger == nil { return cfg // Return defaults if no logger is provided (e.g. in tests) @@ -171,18 +180,20 @@ func Load(logger *log.Logger) App { configPath, err := getConfigPath() if err != nil { logger.Printf("%v", err) - // Even if config path cannot be resolved, still allow env overrides below. + // Even if config path cannot be resolved, keep defaults and optionally apply env overrides below. } else { if fileCfg, err := loadFromFile(configPath, logger); err == nil && fileCfg != nil { cfg.mergeWith(fileCfg) } // When the config file is missing or invalid, we keep defaults and still - // apply any environment overrides below. + // apply any environment overrides below (unless disabled). } - // Environment overrides (take precedence over file) - if envCfg := loadFromEnv(logger); envCfg != nil { - cfg.mergeWith(envCfg) + if !opts.IgnoreEnv { + // Environment overrides (take precedence over file) + if envCfg := loadFromEnv(logger); envCfg != nil { + cfg.mergeWith(envCfg) + } } return cfg } -- cgit v1.2.3