tighten up shell-local config validation
This commit is contained in:
parent
479d36734d
commit
f799003b66
@ -75,6 +75,7 @@ func Validate(config *Config) error {
|
|||||||
"{{.Vars}}",
|
"{{.Vars}}",
|
||||||
"{{.Script}}",
|
"{{.Script}}",
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if config.InlineShebang == "" {
|
if config.InlineShebang == "" {
|
||||||
config.InlineShebang = "/bin/sh -e"
|
config.InlineShebang = "/bin/sh -e"
|
||||||
@ -110,32 +111,32 @@ func Validate(config *Config) error {
|
|||||||
errors.New("Command, Inline, Script and Scripts options cannot all be empty."))
|
errors.New("Command, Inline, Script and Scripts options cannot all be empty."))
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Command != "" {
|
// Check that user hasn't given us too many commands to run
|
||||||
// Backwards Compatibility: Before v1.2.2, the shell-local
|
tooManyOptionsErr := errors.New("You may only specify one of the " +
|
||||||
// provisioner only allowed a single Command, and to run
|
"following options: Command, Inline, Script or Scripts. Please" +
|
||||||
// multiple commands you needed to run several provisioners in a
|
" consolidate these options in your config.")
|
||||||
// row, one for each command. In deduplicating the post-processor and
|
|
||||||
// provisioner code, we've changed this to allow an array of scripts or
|
|
||||||
// inline commands just like in the post-processor. This conditional
|
|
||||||
// grandfathers in the "Command" option, allowing the original usage to
|
|
||||||
// continue to work.
|
|
||||||
config.Inline = append(config.Inline, config.Command)
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.Script != "" && len(config.Scripts) > 0 {
|
if config.Command != "" {
|
||||||
errs = packer.MultiErrorAppend(errs,
|
if len(config.Inline) != 0 || len(config.Scripts) != 0 || config.Script != "" {
|
||||||
errors.New("Only one of script or scripts can be specified."))
|
errs = packer.MultiErrorAppend(errs, tooManyOptionsErr)
|
||||||
|
} else {
|
||||||
|
config.Inline = []string{config.Command}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Script != "" {
|
if config.Script != "" {
|
||||||
config.Scripts = []string{config.Script}
|
if len(config.Scripts) > 0 || len(config.Inline) > 0 {
|
||||||
|
errs = packer.MultiErrorAppend(errs, tooManyOptionsErr)
|
||||||
|
} else {
|
||||||
|
config.Scripts = []string{config.Script}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.Scripts) > 0 && config.Inline != nil {
|
if len(config.Scripts) > 0 && config.Inline != nil {
|
||||||
errs = packer.MultiErrorAppend(errs,
|
errs = packer.MultiErrorAppend(errs, tooManyOptionsErr)
|
||||||
errors.New("You may specify either a script file(s) or an inline script(s), but not both."))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that all scripts we need to run exist locally
|
||||||
for _, path := range config.Scripts {
|
for _, path := range config.Scripts {
|
||||||
if _, err := os.Stat(path); err != nil {
|
if _, err := os.Stat(path); err != nil {
|
||||||
errs = packer.MultiErrorAppend(errs,
|
errs = packer.MultiErrorAppend(errs,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user