Skip to content

Commit

Permalink
Allow for env var to determine config dir (#210)
Browse files Browse the repository at this point in the history
Signed-off-by: jolheiser <john.olheiser@gmail.com>
  • Loading branch information
jolheiser committed May 8, 2023
1 parent 9f42c4d commit 107362f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ func (cfg *Config) Load(file string) error {

// GetDefaultConfigDir returns the default config directory
func GetDefaultConfigDir() (dir string, err error) {
if runtime.GOOS == "windows" {
if env, ok := os.LookupEnv("PET_CONFIG_DIR"); ok {
dir = env
} else if runtime.GOOS == "windows" {
dir = os.Getenv("APPDATA")
if dir == "" {
dir = filepath.Join(os.Getenv("USERPROFILE"), "Application Data", "pet")
Expand All @@ -126,7 +128,7 @@ func GetDefaultConfigDir() (dir string, err error) {
} else {
dir = filepath.Join(os.Getenv("HOME"), ".config", "pet")
}
if err := os.MkdirAll(dir, 0700); err != nil {
if err := os.MkdirAll(dir, 0o700); err != nil {
return "", fmt.Errorf("cannot create directory: %v", err)
}
return dir, nil
Expand Down

0 comments on commit 107362f

Please sign in to comment.