summaryrefslogtreecommitdiffhomepage
path: root/internal/config
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-13 13:17:17 +0200
committerKujtim Hoxha <[email protected]>2025-04-21 13:41:25 +0200
commit3ad983db0f2c08826d56cb5de274d706c95b3353 (patch)
tree3151e7f361dc2b468429791d581eb5f3d658f84f /internal/config
parent5601466fe1610b777895682050b1b458f80c0ac8 (diff)
downloadopencode-3ad983db0f2c08826d56cb5de274d706c95b3353.tar.gz
opencode-3ad983db0f2c08826d56cb5de274d706c95b3353.zip
cleanup app, config and root
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go20
1 files changed, 6 insertions, 14 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 6f757b3f4..1f3091ff3 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -83,9 +83,9 @@ var cfg *Config
// Load initializes the configuration from environment variables and config files.
// If debug is true, debug mode is enabled and log level is set to debug.
// It returns an error if configuration loading fails.
-func Load(workingDir string, debug bool) error {
+func Load(workingDir string, debug bool) (*Config, error) {
if cfg != nil {
- return nil
+ return cfg, nil
}
cfg = &Config{
@@ -101,7 +101,7 @@ func Load(workingDir string, debug bool) error {
// Read global config
if err := readConfig(viper.ReadInConfig()); err != nil {
- return err
+ return cfg, err
}
// Load and merge local config
@@ -109,7 +109,7 @@ func Load(workingDir string, debug bool) error {
// Apply configuration to the struct
if err := viper.Unmarshal(cfg); err != nil {
- return err
+ return cfg, fmt.Errorf("failed to unmarshal config: %w", err)
}
applyDefaultValues()
@@ -123,7 +123,7 @@ func Load(workingDir string, debug bool) error {
Level: defaultLevel,
}))
slog.SetDefault(logger)
- return nil
+ return cfg, nil
}
// configureViper sets up viper's configuration paths and environment variables.
@@ -237,7 +237,7 @@ func readConfig(err error) error {
return nil
}
- return err
+ return fmt.Errorf("failed to read config: %w", err)
}
// mergeLocalConfig loads and merges configuration from the local directory.
@@ -264,14 +264,6 @@ func applyDefaultValues() {
}
}
-// setWorkingDirectory stores the current working directory in the configuration.
-func setWorkingDirectory() {
- workdir, err := os.Getwd()
- if err == nil {
- viper.Set("wd", workdir)
- }
-}
-
// Get returns the current configuration.
// It's safe to call this function multiple times.
func Get() *Config {