helper/config: error if unused keys
This commit is contained in:
parent
becd6dacd7
commit
bdb9bd7dc5
|
@ -1,8 +1,12 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/mitchellh/packer/template/interpolate"
|
"github.com/mitchellh/packer/template/interpolate"
|
||||||
)
|
)
|
||||||
|
@ -70,6 +74,21 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we have unused keys, it is an error
|
||||||
|
if len(md.Unused) > 0 {
|
||||||
|
var err error
|
||||||
|
sort.Strings(md.Unused)
|
||||||
|
for _, unused := range md.Unused {
|
||||||
|
if unused != "type" && !strings.HasPrefix(unused, "packer_") {
|
||||||
|
err = multierror.Append(err, fmt.Errorf(
|
||||||
|
"unknown configuration key: %q", unused))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue