From 1133e5047b24cae6a932c15189f81897b74697a4 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 9 Jul 2024 10:47:44 -0300 Subject: [PATCH] fix: config failing in tests (#625) Signed-off-by: Carlos Alexandro Becker --- config_cmd.go | 4 ++-- main.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/config_cmd.go b/config_cmd.go index adce1de..104b010 100644 --- a/config_cmd.go +++ b/config_cmd.go @@ -53,12 +53,12 @@ func ensureConfigFile() error { if configFile == "" { configFile = viper.GetViper().ConfigFileUsed() if err := os.MkdirAll(filepath.Dir(configFile), 0o755); err != nil { - return fmt.Errorf("Could not write config file: %w", err) + return fmt.Errorf("could not write configuration file: %w", err) } } if ext := path.Ext(configFile); ext != ".yaml" && ext != ".yml" { - return fmt.Errorf("'%s' is not a supported config type: use '%s' or '%s'", ext, ".yaml", ".yml") + return fmt.Errorf("'%s' is not a supported configuration type: use '%s' or '%s'", ext, ".yaml", ".yml") } if _, err := os.Stat(configFile); os.IsNotExist(err) { diff --git a/main.go b/main.go index f1791ec..fdef25d 100644 --- a/main.go +++ b/main.go @@ -400,12 +400,12 @@ func tryLoadConfigFromDefaultPlaces() { os.Exit(1) } - if c := os.Getenv("CHARM_CONFIG_HOME"); c != "" { - viper.AddConfigPath(c) + if c := os.Getenv("XDG_CONFIG_HOME"); c != "" { + dirs = append([]string{filepath.Join(c, "glow")}, dirs...) } - if c := os.Getenv("XDG_CONFIG_HOME"); c != "" { - viper.AddConfigPath(filepath.Join(c, "glow")) + if c := os.Getenv("GLOW_CONFIG_HOME"); c != "" { + dirs = append([]string{c}, dirs...) } for _, v := range dirs { @@ -428,8 +428,11 @@ func tryLoadConfigFromDefaultPlaces() { return } + if viper.ConfigFileUsed() == "" { + configFile = filepath.Join(dirs[0], "glow.yml") + } if err := ensureConfigFile(); err != nil { - fmt.Println("Could not create default configuration.") + log.Error("Could not create default configuration", "error", err) os.Exit(1) } }