github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/util/configv3/home_dir_windows.go (about)

     1  //go:build windows
     2  // +build windows
     3  
     4  package configv3
     5  
     6  import (
     7  	"os"
     8  	"path/filepath"
     9  )
    10  
    11  // ConfigFilePath returns the location of the config file
    12  func ConfigFilePath() string {
    13  	return filepath.Join(homeDirectory(), ".cf", "config.json")
    14  }
    15  
    16  func configDirectory() string {
    17  	return filepath.Join(homeDirectory(), ".cf")
    18  }
    19  
    20  // See: http://stackoverflow.com/questions/7922270/obtain-users-home-directory
    21  // we can't cross compile using cgo and use user.Current()
    22  func homeDirectory() string {
    23  	var homeDir string
    24  	switch {
    25  	case os.Getenv("CF_HOME") != "":
    26  		homeDir = os.Getenv("CF_HOME")
    27  	case os.Getenv("HOMEDRIVE")+os.Getenv("HOMEPATH") != "":
    28  		homeDir = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
    29  	default:
    30  		homeDir = os.Getenv("USERPROFILE")
    31  	}
    32  	return homeDir
    33  }