Skip to content

Commit

Permalink
fixing windows support;simplifying considerably
Browse files Browse the repository at this point in the history
  • Loading branch information
lleadbet committed Aug 16, 2021
1 parent 8df7b3b commit 92604a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 7 additions & 16 deletions internal/util/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,29 @@ import (
"os"
"path/filepath"
"runtime"

"github.com/mitchellh/go-homedir"
)

var legacySubFolder = ".twitch-cli"
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) {
Expand Down

0 comments on commit 92604a2

Please sign in to comment.