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,18 +52,31 @@ func homeDir() (string, error) {
} }
func configFile() (string, error) { func configFile() (string, error) {
dir, err := homeDir() var dir string
if err != nil { if cd := os.Getenv("PACKER_CONFIG_DIR"); cd != "" {
return "", err 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 return filepath.Join(dir, defaultConfigFile), nil
} }
func configDir() (string, error) { func configDir() (string, error) {
dir, err := homeDir() var dir string
if err != nil { if cd := os.Getenv("PACKER_CONFIG_DIR"); cd != "" {
return "", err 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 return filepath.Join(dir, defaultConfigDir), nil