fix: condensed and simplified os check logic and added validate output

This commit is contained in:
Joel Vasallo 2018-10-19 13:48:30 -05:00
parent d408c9e69c
commit 23ad90f2c4
2 changed files with 8 additions and 9 deletions

View File

@ -175,7 +175,8 @@ func Validate(config *Config) error {
} }
} }
if supported_os != true { if supported_os != true {
return fmt.Errorf("Invalid OS specified in only_on: '%s'", provided_os) return fmt.Errorf("Invalid OS specified in only_on: '%s'\n"+
"Supported OS names: %v", provided_os, supported_syslist)
} }
} }
} }

View File

@ -29,21 +29,19 @@ type EnvVarsTemplate struct {
func Run(ui packer.Ui, config *Config) (bool, error) { func Run(ui packer.Ui, config *Config) (bool, error) {
// Check if shell-local can even execute against this runtime OS // Check if shell-local can even execute against this runtime OS
runCommand := false
if len(config.OnlyOn) > 0 { if len(config.OnlyOn) > 0 {
runCommand := false
for _, os := range config.OnlyOn { for _, os := range config.OnlyOn {
if os == runtime.GOOS { if os == runtime.GOOS {
runCommand = true runCommand = true
break break
} }
} }
} else { if !runCommand {
runCommand = true ui.Say(fmt.Sprintf("Skipping shell-local due to runtime OS"))
} log.Printf("[INFO] (shell-local): skipping shell-local due to missing runtime OS")
if !runCommand { return true, nil
ui.Say(fmt.Sprintf("Skipping shell-local due to runtime OS")) }
log.Printf("[INFO] (shell-local): skipping shell-local due to missing runtime OS")
return true, nil
} }
scripts := make([]string, len(config.Scripts)) scripts := make([]string, len(config.Scripts))