check env for a PACKER_CONFIG_DIR before defaulting to homedir for config

This commit is contained in:
Megan Marsh 2019-07-25 13:06:41 -07:00
parent 140785f088
commit 5d4d5a21bf
1 changed files with 20 additions and 7 deletions

View File

@ -52,19 +52,32 @@ func homeDir() (string, error) {
}
func configFile() (string, error) {
dir, err := homeDir()
var dir string
if cd := os.Getenv("PACKER_CONFIG_DIR"); cd != "" {
log.Printf("Detected config directory from env var: %s", cd)
dir = cd
} else {
homedir, err := homeDir()
if err != nil {
return "", err
}
dir = homedir
}
return filepath.Join(dir, defaultConfigFile), nil
}
func configDir() (string, error) {
dir, err := homeDir()
var dir string
if cd := os.Getenv("PACKER_CONFIG_DIR"); cd != "" {
log.Printf("Detected config directory from env var: %s", cd)
dir = cd
} else {
homedir, err := homeDir()
if err != nil {
return "", err
}
dir = homedir
}
return filepath.Join(dir, defaultConfigDir), nil
}