diff --git a/go.mod b/go.mod index 8783f760..985dc42a 100755 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/manifoldco/promptui v0.8.0 github.com/mattn/go-isatty v0.0.13 // indirect github.com/mattn/go-sqlite3 v1.14.7 - github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/pelletier/go-toml v1.9.2 // indirect github.com/spf13/afero v1.6.0 // indirect diff --git a/internal/util/path.go b/internal/util/path.go index c90f4e89..0ed804e7 100644 --- a/internal/util/path.go +++ b/internal/util/path.go @@ -8,8 +8,6 @@ import ( "os" "path/filepath" "runtime" - - "github.com/mitchellh/go-homedir" ) var legacySubFolder = ".twitch-cli" @@ -17,29 +15,22 @@ var subFolder = "twitch-cli" // GetApplicationDir returns a string representation of the home path for use with configuration/data storage needs func GetApplicationDir() (string, error) { - home, err := homedir.Dir() + home, err := os.UserHomeDir() if err != nil { return "", err } + // check if the home/.twitch-cli folder exists; if so, use that as the path if _, err := os.Stat(filepath.Join(home, ".twitch-cli")); !os.IsNotExist(err) { return filepath.Join(home, ".twitch-cli"), nil } - path := "" - - xdg, exists := os.LookupEnv("XDG_CONFIG_HOME") // per comment in PR #71- using this env var if present - if !exists || xdg == "" { - // if not present, set sane defaults- APPDATA\twitch-cli for Windows, .config/twitch-cli for OSX/Linux - if runtime.GOOS == "WINDOWS" { - path = filepath.Join("$APPDATA", subFolder) - } else { - path = filepath.Join(home, ".config", subFolder) - } - } else { - // if it does exist, then just use it and combine with the subfolder; example is: $HOME/.config/twitch-cli - path = filepath.Join(xdg, subFolder) + // handles the XDG_CONFIG_HOME var as well as using AppData + configPath, err := os.UserConfigDir() + if err != nil { + return "", err } + path := filepath.Join(configPath, subFolder) // if the full path doesn't exist, make all the folders to get there if _, err := os.Stat(path); os.IsNotExist(err) {