Commit 42059f9b authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/*: extract to common the config decoding

parent e84669aa
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/builder/common" "github.com/mitchellh/packer/builder/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
...@@ -61,24 +60,11 @@ type Builder struct { ...@@ -61,24 +60,11 @@ type Builder struct {
} }
func (b *Builder) Prepare(raws ...interface{}) error { func (b *Builder) Prepare(raws ...interface{}) error {
var md mapstructure.Metadata md, err := common.DecodeConfig(&b.config, raws...)
decoderConfig := &mapstructure.DecoderConfig{
Metadata: &md,
Result: &b.config,
}
decoder, err := mapstructure.NewDecoder(decoderConfig)
if err != nil { if err != nil {
return err return err
} }
for _, raw := range raws {
err := decoder.Decode(raw)
if err != nil {
return err
}
}
// Accumulate any errors // Accumulate any errors
errs := make([]error, 0) errs := make([]error, 0)
......
...@@ -3,7 +3,6 @@ package virtualbox ...@@ -3,7 +3,6 @@ package virtualbox
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/builder/common" "github.com/mitchellh/packer/builder/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
...@@ -65,24 +64,11 @@ type config struct { ...@@ -65,24 +64,11 @@ type config struct {
} }
func (b *Builder) Prepare(raws ...interface{}) error { func (b *Builder) Prepare(raws ...interface{}) error {
var md mapstructure.Metadata md, err := common.DecodeConfig(&b.config, raws...)
decoderConfig := &mapstructure.DecoderConfig{
Metadata: &md,
Result: &b.config,
}
decoder, err := mapstructure.NewDecoder(decoderConfig)
if err != nil { if err != nil {
return err return err
} }
for _, raw := range raws {
err := decoder.Decode(raw)
if err != nil {
return err
}
}
// Accumulate any errors // Accumulate any errors
errs := make([]error, 0) errs := make([]error, 0)
......
...@@ -3,7 +3,6 @@ package vmware ...@@ -3,7 +3,6 @@ package vmware
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/builder/common" "github.com/mitchellh/packer/builder/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
...@@ -66,24 +65,11 @@ type config struct { ...@@ -66,24 +65,11 @@ type config struct {
} }
func (b *Builder) Prepare(raws ...interface{}) error { func (b *Builder) Prepare(raws ...interface{}) error {
var md mapstructure.Metadata md, err := common.DecodeConfig(&b.config, raws...)
decoderConfig := &mapstructure.DecoderConfig{
Metadata: &md,
Result: &b.config,
}
decoder, err := mapstructure.NewDecoder(decoderConfig)
if err != nil { if err != nil {
return err return err
} }
for _, raw := range raws {
err := decoder.Decode(raw)
if err != nil {
return err
}
}
// Accumulate any errors // Accumulate any errors
errs := make([]error, 0) errs := make([]error, 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment