deps: Update github.com/hashicorp/hil/...

This commit is contained in:
James Nugent 2016-06-03 13:32:07 -05:00
parent 49995428fd
commit 819bd3fba3
4 changed files with 43 additions and 11 deletions

View File

@ -1,3 +0,0 @@
.DS_Store
.idea
*.iml

View File

@ -1,3 +0,0 @@
sudo: false
language: go
go: 1.5

View File

@ -2,14 +2,48 @@ package hil
import ( import (
"fmt" "fmt"
"reflect"
"github.com/hashicorp/hil/ast" "github.com/hashicorp/hil/ast"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
) )
var hilMapstructureDecodeHookSlice []interface{}
var hilMapstructureDecodeHookStringSlice []string
var hilMapstructureDecodeHookMap map[string]interface{}
// hilMapstructureWeakDecode behaves in the same way as mapstructure.WeakDecode
// but has a DecodeHook which defeats the backward compatibility mode of mapstructure
// which WeakDecodes []interface{}{} into an empty map[string]interface{}. This
// allows us to use WeakDecode (desirable), but not fail on empty lists.
func hilMapstructureWeakDecode(m interface{}, rawVal interface{}) error {
config := &mapstructure.DecoderConfig{
DecodeHook: func(source reflect.Type, target reflect.Type, val interface{}) (interface{}, error) {
sliceType := reflect.TypeOf(hilMapstructureDecodeHookSlice)
stringSliceType := reflect.TypeOf(hilMapstructureDecodeHookStringSlice)
mapType := reflect.TypeOf(hilMapstructureDecodeHookMap)
if (source == sliceType || source == stringSliceType) && target == mapType {
return nil, fmt.Errorf("Cannot convert %s into a %s", source, target)
}
return val, nil
},
WeaklyTypedInput: true,
Result: rawVal,
}
decoder, err := mapstructure.NewDecoder(config)
if err != nil {
return err
}
return decoder.Decode(m)
}
func InterfaceToVariable(input interface{}) (ast.Variable, error) { func InterfaceToVariable(input interface{}) (ast.Variable, error) {
var stringVal string var stringVal string
if err := mapstructure.WeakDecode(input, &stringVal); err == nil { if err := hilMapstructureWeakDecode(input, &stringVal); err == nil {
return ast.Variable{ return ast.Variable{
Type: ast.TypeString, Type: ast.TypeString,
Value: stringVal, Value: stringVal,
@ -17,7 +51,7 @@ func InterfaceToVariable(input interface{}) (ast.Variable, error) {
} }
var mapVal map[string]interface{} var mapVal map[string]interface{}
if err := mapstructure.WeakDecode(input, &mapVal); err == nil { if err := hilMapstructureWeakDecode(input, &mapVal); err == nil {
elements := make(map[string]ast.Variable) elements := make(map[string]ast.Variable)
for i, element := range mapVal { for i, element := range mapVal {
varElement, err := InterfaceToVariable(element) varElement, err := InterfaceToVariable(element)
@ -34,7 +68,7 @@ func InterfaceToVariable(input interface{}) (ast.Variable, error) {
} }
var sliceVal []interface{} var sliceVal []interface{}
if err := mapstructure.WeakDecode(input, &sliceVal); err == nil { if err := hilMapstructureWeakDecode(input, &sliceVal); err == nil {
elements := make([]ast.Variable, len(sliceVal)) elements := make([]ast.Variable, len(sliceVal))
for i, element := range sliceVal { for i, element := range sliceVal {
varElement, err := InterfaceToVariable(element) varElement, err := InterfaceToVariable(element)

8
vendor/vendor.json vendored
View File

@ -836,12 +836,16 @@
"revisionTime": "2016-06-07T00:19:40Z" "revisionTime": "2016-06-07T00:19:40Z"
}, },
{ {
"checksumSHA1": "rYMJhG5J/OzcBIRfatklb/+JrJ4=",
"path": "github.com/hashicorp/hil", "path": "github.com/hashicorp/hil",
"revision": "01dc167cd239b7ccab78a683b866536cd5904719" "revision": "58c35af3b2c3a72c572851bc9e650b62a61d5ec2",
"revisionTime": "2016-06-05T07:46:40Z"
}, },
{ {
"checksumSHA1": "eJv3RKa2gk/4khPzo3+pJzThz8w=",
"path": "github.com/hashicorp/hil/ast", "path": "github.com/hashicorp/hil/ast",
"revision": "01dc167cd239b7ccab78a683b866536cd5904719" "revision": "42cfb33535beaca9a8ca2ef415930a1bd8f32998",
"revisionTime": "2016-06-03T20:14:09Z"
}, },
{ {
"path": "github.com/hashicorp/logutils", "path": "github.com/hashicorp/logutils",