Skip to content

Commit

Permalink
fix: make config path lookup windows compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
ludviglundgren committed Apr 5, 2024
1 parent bc5431d commit 9d68723
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package config

import (
"errors"
"fmt"
"os"
"path/filepath"

"github.com/ludviglundgren/qbittorrent-cli/internal/domain"

Expand Down Expand Up @@ -32,19 +34,21 @@ func InitConfig() {
os.Exit(1)
}

// Search config in directories
viper.SetConfigName(".qbt")
// Search config in directories
// call multiple times to add many search paths
viper.AddConfigPath(".") // optionally look for config in the working directory
viper.AddConfigPath(home)
viper.AddConfigPath(home + "/.config/qbt")
viper.AddConfigPath("$HOME/.config/qbt") // call multiple times to add many search paths
viper.AddConfigPath(filepath.Join(home, ".config", "qbt")) // windows path
viper.AddConfigPath("$HOME/.config/qbt")
}

if err := viper.ReadInConfig(); err != nil {
if ferr, ok := err.(*viper.ConfigFileNotFoundError); ok {
var ferr *viper.ConfigFileNotFoundError
if errors.As(err, &ferr) {
fmt.Printf("config file not found: err %q\n", ferr)
} else {
fmt.Println("Could not read config file:", err)
fmt.Printf("could not read config: err %q\n", err)
}
os.Exit(1)
}
Expand Down

0 comments on commit 9d68723

Please sign in to comment.