mirror of
https://github.com/charmbracelet/glow
synced 2024-11-10 06:04:18 +00:00
fix: config failing in tests (#625)
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
f44e5b5f5c
commit
1133e5047b
2 changed files with 10 additions and 7 deletions
|
@ -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) {
|
||||
|
|
13
main.go
13
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue