github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/configuration/config_helpers/config_helpers.go (about)

     1  package config_helpers
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"runtime"
     7  )
     8  
     9  func DefaultFilePath() string {
    10  	var configDir string
    11  
    12  	if os.Getenv("CF_HOME") != "" {
    13  		cfHome := os.Getenv("CF_HOME")
    14  		configDir = filepath.Join(cfHome, ".cf")
    15  	} else {
    16  		configDir = filepath.Join(userHomeDir(), ".cf")
    17  	}
    18  
    19  	return filepath.Join(configDir, "config.json")
    20  }
    21  
    22  // See: http://stackoverflow.com/questions/7922270/obtain-users-home-directory
    23  // we can't cross compile using cgo and use user.Current()
    24  var userHomeDir = func() string {
    25  
    26  	if runtime.GOOS == "windows" {
    27  		home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
    28  		if home == "" {
    29  			home = os.Getenv("USERPROFILE")
    30  		}
    31  		return home
    32  	}
    33  
    34  	return os.Getenv("HOME")
    35  }
    36  
    37  var PluginRepoDir = func() string {
    38  	if os.Getenv("CF_PLUGIN_HOME") != "" {
    39  		return os.Getenv("CF_PLUGIN_HOME")
    40  	}
    41  
    42  	return userHomeDir()
    43  }