summaryrefslogtreecommitdiff
path: root/internal/appconfig
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-28 17:30:44 +0300
committerPaul Buetow <paul@buetow.org>2025-09-28 17:30:44 +0300
commit0761409497041c752086b9aded08cf9e32e30fd2 (patch)
treee62721bc119d4ae435d2609292faea06a68244a4 /internal/appconfig
parent0ac2d186e84f77d73d924e2c0ce975a17c3a8078 (diff)
Add --config flag support across CLI, LSP, and tmux tools
Diffstat (limited to 'internal/appconfig')
-rw-r--r--internal/appconfig/config.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/internal/appconfig/config.go b/internal/appconfig/config.go
index 27c7e02..1b134ee 100644
--- a/internal/appconfig/config.go
+++ b/internal/appconfig/config.go
@@ -180,7 +180,8 @@ 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
+ IgnoreEnv bool
+ ConfigPath string
}
// LoadWithOptions reads configuration and applies the requested loading options.
@@ -190,16 +191,20 @@ func LoadWithOptions(logger *log.Logger, opts LoadOptions) App {
return cfg // Return defaults if no logger is provided (e.g. in tests)
}
- configPath, err := getConfigPath()
- if err != nil {
- logger.Printf("%v", err)
- // Even if config path cannot be resolved, keep defaults and optionally apply env overrides below.
- } else {
+ configPath := strings.TrimSpace(opts.ConfigPath)
+ if configPath != "" {
if fileCfg, err := loadFromFile(configPath, logger); err == nil && fileCfg != nil {
cfg.mergeWith(fileCfg)
+ } else if err != nil {
+ logger.Printf("cannot open config file %s: %v", configPath, err)
+ }
+ } else {
+ path, err := getConfigPath()
+ if err != nil {
+ logger.Printf("%v", err)
+ } else if fileCfg, err := loadFromFile(path, 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 (unless disabled).
}
if !opts.IgnoreEnv {