Browse Source

Updated vendor packages

maze 8 months ago
parent
commit
6f05d60c3d
100 changed files with 6681 additions and 41 deletions
  1. 27
    0
      Gopkg.lock
  2. 34
    0
      Gopkg.toml
  3. 16
    5
      vendor/github.com/hashicorp/golang-lru/2q.go
  4. 8
    8
      vendor/github.com/hashicorp/golang-lru/arc.go
  5. 21
    0
      vendor/github.com/hashicorp/golang-lru/doc.go
  6. 1
    0
      vendor/github.com/hashicorp/golang-lru/go.mod
  7. 12
    16
      vendor/github.com/hashicorp/golang-lru/lru.go
  8. 2
    2
      vendor/github.com/hashicorp/golang-lru/lru_test.go
  9. 9
    8
      vendor/github.com/hashicorp/golang-lru/simplelru/lru.go
  10. 36
    0
      vendor/github.com/hashicorp/golang-lru/simplelru/lru_interface.go
  11. 2
    2
      vendor/github.com/hashicorp/golang-lru/simplelru/lru_test.go
  12. 21
    0
      vendor/github.com/hashicorp/hcl/.github/ISSUE_TEMPLATE.md
  13. 9
    0
      vendor/github.com/hashicorp/hcl/.gitignore
  14. 13
    0
      vendor/github.com/hashicorp/hcl/.travis.yml
  15. 354
    0
      vendor/github.com/hashicorp/hcl/LICENSE
  16. 18
    0
      vendor/github.com/hashicorp/hcl/Makefile
  17. 125
    0
      vendor/github.com/hashicorp/hcl/README.md
  18. 19
    0
      vendor/github.com/hashicorp/hcl/appveyor.yml
  19. 729
    0
      vendor/github.com/hashicorp/hcl/decoder.go
  20. 1203
    0
      vendor/github.com/hashicorp/hcl/decoder_test.go
  21. 3
    0
      vendor/github.com/hashicorp/hcl/go.mod
  22. 2
    0
      vendor/github.com/hashicorp/hcl/go.sum
  23. 11
    0
      vendor/github.com/hashicorp/hcl/hcl.go
  24. 219
    0
      vendor/github.com/hashicorp/hcl/hcl/ast/ast.go
  25. 200
    0
      vendor/github.com/hashicorp/hcl/hcl/ast/ast_test.go
  26. 52
    0
      vendor/github.com/hashicorp/hcl/hcl/ast/walk.go
  27. 162
    0
      vendor/github.com/hashicorp/hcl/hcl/fmtcmd/fmtcmd.go
  28. 440
    0
      vendor/github.com/hashicorp/hcl/hcl/fmtcmd/fmtcmd_test.go
  29. 1
    0
      vendor/github.com/hashicorp/hcl/hcl/fmtcmd/test-fixtures/.hidden.ignore
  30. 0
    0
      vendor/github.com/hashicorp/hcl/hcl/fmtcmd/test-fixtures/dir.ignore
  31. 1
    0
      vendor/github.com/hashicorp/hcl/hcl/fmtcmd/test-fixtures/file.ignore
  32. 0
    0
      vendor/github.com/hashicorp/hcl/hcl/fmtcmd/test-fixtures/good.hcl
  33. 17
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/error.go
  34. 9
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/error_test.go
  35. 532
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/parser.go
  36. 575
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/parser_test.go
  37. 4
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/array_comment.hcl
  38. 6
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/array_comment_2.hcl
  39. 6
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/assign_colon.hcl
  40. 5
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/assign_deep.hcl
  41. 15
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/comment.hcl
  42. 15
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/comment_crlf.hcl
  43. 1
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/comment_lastline.hcl
  44. 1
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/comment_single.hcl
  45. 42
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/complex.hcl
  46. 42
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/complex_crlf.hcl
  47. 1
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/complex_key.hcl
  48. 0
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/empty.hcl
  49. BIN
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/git_crypt.hcl
  50. 1
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/key_without_value.hcl
  51. 1
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/list.hcl
  52. 1
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/list_comma.hcl
  53. 4
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/missing_braces.hcl
  54. 2
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/multiple.hcl
  55. 3
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/object_key_assign_without_value.hcl
  56. 4
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/object_key_assign_without_value2.hcl
  57. 4
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/object_key_assign_without_value3.hcl
  58. 3
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/object_key_without_value.hcl
  59. 1
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/object_list_comma.hcl
  60. 3
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/old.hcl
  61. 5
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/structure.hcl
  62. 5
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/structure_basic.hcl
  63. 1
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/structure_empty.hcl
  64. 7
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/types.hcl
  65. 2
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/unterminated_object.hcl
  66. 6
    0
      vendor/github.com/hashicorp/hcl/hcl/parser/test-fixtures/unterminated_object_2.hcl
  67. 789
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/nodes.go
  68. 66
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/printer.go
  69. 176
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/printer_test.go
  70. 39
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment.golden
  71. 39
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment.input
  72. 32
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_aligned.golden
  73. 28
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_aligned.input
  74. 13
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_array.golden
  75. 13
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_array.input
  76. 39
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_crlf.input
  77. 6
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_end_file.golden
  78. 5
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_end_file.input
  79. 12
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_multiline_indent.golden
  80. 13
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_multiline_indent.input
  81. 7
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_multiline_no_stanza.golden
  82. 6
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_multiline_no_stanza.input
  83. 10
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_multiline_stanza.golden
  84. 10
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_multiline_stanza.input
  85. 3
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_newline.golden
  86. 2
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_newline.input
  87. 9
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_object_multi.golden
  88. 9
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_object_multi.input
  89. 17
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_standalone.golden
  90. 16
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/comment_standalone.input
  91. 54
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/complexhcl.golden
  92. 53
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/complexhcl.input
  93. 12
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/empty_block.golden
  94. 14
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/empty_block.input
  95. 46
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/list.golden
  96. 37
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/list.input
  97. 13
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/list_comment.golden
  98. 9
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/list_comment.input
  99. 10
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/list_of_objects.golden
  100. 0
    0
      vendor/github.com/hashicorp/hcl/hcl/printer/testdata/list_of_objects.input

+ 27
- 0
Gopkg.lock View File

@@ -0,0 +1,27 @@
1
+# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
2
+
3
+
4
+[[projects]]
5
+  name = "github.com/hashicorp/golang-lru"
6
+  packages = [".","simplelru"]
7
+  revision = "20f1fb78b0740ba8c3cb143a61e86ba5c8669768"
8
+  version = "v0.5.0"
9
+
10
+[[projects]]
11
+  name = "github.com/hashicorp/hcl"
12
+  packages = [".","hcl/ast","hcl/parser","hcl/scanner","hcl/strconv","hcl/token","json/parser","json/scanner","json/token"]
13
+  revision = "8cb6e5b959231cc1119e43259c4a608f9c51a241"
14
+  version = "v1.0.0"
15
+
16
+[[projects]]
17
+  branch = "v0"
18
+  name = "gopkg.in/opensmtpd.v0"
19
+  packages = ["."]
20
+  revision = "27c2eae88fcfa0ce76429f3f4a7c3399466ea7d5"
21
+
22
+[solve-meta]
23
+  analyzer-name = "dep"
24
+  analyzer-version = 1
25
+  inputs-digest = "b1622df9f63b5e3728506bf5396befa379916fa781167f07b84c039a865eb4b2"
26
+  solver-name = "gps-cdcl"
27
+  solver-version = 1

+ 34
- 0
Gopkg.toml View File

@@ -0,0 +1,34 @@
1
+
2
+# Gopkg.toml example
3
+#
4
+# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
5
+# for detailed Gopkg.toml documentation.
6
+#
7
+# required = ["github.com/user/thing/cmd/thing"]
8
+# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
9
+#
10
+# [[constraint]]
11
+#   name = "github.com/user/project"
12
+#   version = "1.0.0"
13
+#
14
+# [[constraint]]
15
+#   name = "github.com/user/project2"
16
+#   branch = "dev"
17
+#   source = "github.com/myfork/project2"
18
+#
19
+# [[override]]
20
+#  name = "github.com/x/y"
21
+#  version = "2.4.0"
22
+
23
+
24
+[[constraint]]
25
+  name = "github.com/hashicorp/golang-lru"
26
+  version = "0.5.0"
27
+
28
+[[constraint]]
29
+  name = "github.com/hashicorp/hcl"
30
+  version = "1.0.0"
31
+
32
+[[constraint]]
33
+  branch = "v0"
34
+  name = "gopkg.in/opensmtpd.v0"

+ 16
- 5
vendor/github.com/hashicorp/golang-lru/2q.go View File

@@ -30,9 +30,9 @@ type TwoQueueCache struct {
30 30
 	size       int
31 31
 	recentSize int
32 32
 
33
-	recent      *simplelru.LRU
34
-	frequent    *simplelru.LRU
35
-	recentEvict *simplelru.LRU
33
+	recent      simplelru.LRUCache
34
+	frequent    simplelru.LRUCache
35
+	recentEvict simplelru.LRUCache
36 36
 	lock        sync.RWMutex
37 37
 }
38 38
 
@@ -84,7 +84,8 @@ func New2QParams(size int, recentRatio float64, ghostRatio float64) (*TwoQueueCa
84 84
 	return c, nil
85 85
 }
86 86
 
87
-func (c *TwoQueueCache) Get(key interface{}) (interface{}, bool) {
87
+// Get looks up a key's value from the cache.
88
+func (c *TwoQueueCache) Get(key interface{}) (value interface{}, ok bool) {
88 89
 	c.lock.Lock()
89 90
 	defer c.lock.Unlock()
90 91
 
@@ -105,6 +106,7 @@ func (c *TwoQueueCache) Get(key interface{}) (interface{}, bool) {
105 106
 	return nil, false
106 107
 }
107 108
 
109
+// Add adds a value to the cache.
108 110
 func (c *TwoQueueCache) Add(key, value interface{}) {
109 111
 	c.lock.Lock()
110 112
 	defer c.lock.Unlock()
@@ -160,12 +162,15 @@ func (c *TwoQueueCache) ensureSpace(recentEvict bool) {
160 162
 	c.frequent.RemoveOldest()
161 163
 }
162 164
 
165
+// Len returns the number of items in the cache.
163 166
 func (c *TwoQueueCache) Len() int {
164 167
 	c.lock.RLock()
165 168
 	defer c.lock.RUnlock()
166 169
 	return c.recent.Len() + c.frequent.Len()
167 170
 }
168 171
 
172
+// Keys returns a slice of the keys in the cache.
173
+// The frequently used keys are first in the returned slice.
169 174
 func (c *TwoQueueCache) Keys() []interface{} {
170 175
 	c.lock.RLock()
171 176
 	defer c.lock.RUnlock()
@@ -174,6 +179,7 @@ func (c *TwoQueueCache) Keys() []interface{} {
174 179
 	return append(k1, k2...)
175 180
 }
176 181
 
182
+// Remove removes the provided key from the cache.
177 183
 func (c *TwoQueueCache) Remove(key interface{}) {
178 184
 	c.lock.Lock()
179 185
 	defer c.lock.Unlock()
@@ -188,6 +194,7 @@ func (c *TwoQueueCache) Remove(key interface{}) {
188 194
 	}
189 195
 }
190 196
 
197
+// Purge is used to completely clear the cache.
191 198
 func (c *TwoQueueCache) Purge() {
192 199
 	c.lock.Lock()
193 200
 	defer c.lock.Unlock()
@@ -196,13 +203,17 @@ func (c *TwoQueueCache) Purge() {
196 203
 	c.recentEvict.Purge()
197 204
 }
198 205
 
206
+// Contains is used to check if the cache contains a key
207
+// without updating recency or frequency.
199 208
 func (c *TwoQueueCache) Contains(key interface{}) bool {
200 209
 	c.lock.RLock()
201 210
 	defer c.lock.RUnlock()
202 211
 	return c.frequent.Contains(key) || c.recent.Contains(key)
203 212
 }
204 213
 
205
-func (c *TwoQueueCache) Peek(key interface{}) (interface{}, bool) {
214
+// Peek is used to inspect the cache value of a key
215
+// without updating recency or frequency.
216
+func (c *TwoQueueCache) Peek(key interface{}) (value interface{}, ok bool) {
206 217
 	c.lock.RLock()
207 218
 	defer c.lock.RUnlock()
208 219
 	if val, ok := c.frequent.Peek(key); ok {

+ 8
- 8
vendor/github.com/hashicorp/golang-lru/arc.go View File

@@ -18,11 +18,11 @@ type ARCCache struct {
18 18
 	size int // Size is the total capacity of the cache
19 19
 	p    int // P is the dynamic preference towards T1 or T2
20 20
 
21
-	t1 *simplelru.LRU // T1 is the LRU for recently accessed items
22
-	b1 *simplelru.LRU // B1 is the LRU for evictions from t1
21
+	t1 simplelru.LRUCache // T1 is the LRU for recently accessed items
22
+	b1 simplelru.LRUCache // B1 is the LRU for evictions from t1
23 23
 
24
-	t2 *simplelru.LRU // T2 is the LRU for frequently accessed items
25
-	b2 *simplelru.LRU // B2 is the LRU for evictions from t2
24
+	t2 simplelru.LRUCache // T2 is the LRU for frequently accessed items
25
+	b2 simplelru.LRUCache // B2 is the LRU for evictions from t2
26 26
 
27 27
 	lock sync.RWMutex
28 28
 }
@@ -60,11 +60,11 @@ func NewARC(size int) (*ARCCache, error) {
60 60
 }
61 61
 
62 62
 // Get looks up a key's value from the cache.
63
-func (c *ARCCache) Get(key interface{}) (interface{}, bool) {
63
+func (c *ARCCache) Get(key interface{}) (value interface{}, ok bool) {
64 64
 	c.lock.Lock()
65 65
 	defer c.lock.Unlock()
66 66
 
67
-	// Ff the value is contained in T1 (recent), then
67
+	// If the value is contained in T1 (recent), then
68 68
 	// promote it to T2 (frequent)
69 69
 	if val, ok := c.t1.Peek(key); ok {
70 70
 		c.t1.Remove(key)
@@ -153,7 +153,7 @@ func (c *ARCCache) Add(key, value interface{}) {
153 153
 		// Remove from B2
154 154
 		c.b2.Remove(key)
155 155
 
156
-		// Add the key to the frequntly used list
156
+		// Add the key to the frequently used list
157 157
 		c.t2.Add(key, value)
158 158
 		return
159 159
 	}
@@ -247,7 +247,7 @@ func (c *ARCCache) Contains(key interface{}) bool {
247 247
 
248 248
 // Peek is used to inspect the cache value of a key
249 249
 // without updating recency or frequency.
250
-func (c *ARCCache) Peek(key interface{}) (interface{}, bool) {
250
+func (c *ARCCache) Peek(key interface{}) (value interface{}, ok bool) {
251 251
 	c.lock.RLock()
252 252
 	defer c.lock.RUnlock()
253 253
 	if val, ok := c.t1.Peek(key); ok {

+ 21
- 0
vendor/github.com/hashicorp/golang-lru/doc.go View File

@@ -0,0 +1,21 @@
1
+// Package lru provides three different LRU caches of varying sophistication.
2
+//
3
+// Cache is a simple LRU cache. It is based on the
4
+// LRU implementation in groupcache:
5
+// https://github.com/golang/groupcache/tree/master/lru
6
+//
7
+// TwoQueueCache tracks frequently used and recently used entries separately.
8
+// This avoids a burst of accesses from taking out frequently used entries,
9
+// at the cost of about 2x computational overhead and some extra bookkeeping.
10
+//
11
+// ARCCache is an adaptive replacement cache. It tracks recent evictions as
12
+// well as recent usage in both the frequent and recent caches. Its
13
+// computational overhead is comparable to TwoQueueCache, but the memory
14
+// overhead is linear with the size of the cache.
15
+//
16
+// ARC has been patented by IBM, so do not use it if that is problematic for
17
+// your program.
18
+//
19
+// All caches in this package take locks while operating, and are therefore
20
+// thread-safe for consumers.
21
+package lru

+ 1
- 0
vendor/github.com/hashicorp/golang-lru/go.mod View File

@@ -0,0 +1 @@
1
+module github.com/hashicorp/golang-lru

+ 12
- 16
vendor/github.com/hashicorp/golang-lru/lru.go View File

@@ -1,6 +1,3 @@
1
-// This package provides a simple LRU cache. It is based on the
2
-// LRU implementation in groupcache:
3
-// https://github.com/golang/groupcache/tree/master/lru
4 1
 package lru
5 2
 
6 3
 import (
@@ -11,11 +8,11 @@ import (
11 8
 
12 9
 // Cache is a thread-safe fixed size LRU cache.
13 10
 type Cache struct {
14
-	lru  *simplelru.LRU
11
+	lru  simplelru.LRUCache
15 12
 	lock sync.RWMutex
16 13
 }
17 14
 
18
-// New creates an LRU of the given size
15
+// New creates an LRU of the given size.
19 16
 func New(size int) (*Cache, error) {
20 17
 	return NewWithEvict(size, nil)
21 18
 }
@@ -33,7 +30,7 @@ func NewWithEvict(size int, onEvicted func(key interface{}, value interface{}))
33 30
 	return c, nil
34 31
 }
35 32
 
36
-// Purge is used to completely clear the cache
33
+// Purge is used to completely clear the cache.
37 34
 func (c *Cache) Purge() {
38 35
 	c.lock.Lock()
39 36
 	c.lru.Purge()
@@ -41,30 +38,30 @@ func (c *Cache) Purge() {
41 38
 }
42 39
 
43 40
 // Add adds a value to the cache.  Returns true if an eviction occurred.
44
-func (c *Cache) Add(key, value interface{}) bool {
41
+func (c *Cache) Add(key, value interface{}) (evicted bool) {
45 42
 	c.lock.Lock()
46 43
 	defer c.lock.Unlock()
47 44
 	return c.lru.Add(key, value)
48 45
 }
49 46
 
50 47
 // Get looks up a key's value from the cache.
51
-func (c *Cache) Get(key interface{}) (interface{}, bool) {
48
+func (c *Cache) Get(key interface{}) (value interface{}, ok bool) {
52 49
 	c.lock.Lock()
53 50
 	defer c.lock.Unlock()
54 51
 	return c.lru.Get(key)
55 52
 }
56 53
 
57
-// Check if a key is in the cache, without updating the recent-ness
58
-// or deleting it for being stale.
54
+// Contains checks if a key is in the cache, without updating the
55
+// recent-ness or deleting it for being stale.
59 56
 func (c *Cache) Contains(key interface{}) bool {
60 57
 	c.lock.RLock()
61 58
 	defer c.lock.RUnlock()
62 59
 	return c.lru.Contains(key)
63 60
 }
64 61
 
65
-// Returns the key value (or undefined if not found) without updating
62
+// Peek returns the key value (or undefined if not found) without updating
66 63
 // the "recently used"-ness of the key.
67
-func (c *Cache) Peek(key interface{}) (interface{}, bool) {
64
+func (c *Cache) Peek(key interface{}) (value interface{}, ok bool) {
68 65
 	c.lock.RLock()
69 66
 	defer c.lock.RUnlock()
70 67
 	return c.lru.Peek(key)
@@ -73,16 +70,15 @@ func (c *Cache) Peek(key interface{}) (interface{}, bool) {
73 70
 // ContainsOrAdd checks if a key is in the cache  without updating the
74 71
 // recent-ness or deleting it for being stale,  and if not, adds the value.
75 72
 // Returns whether found and whether an eviction occurred.
76
-func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evict bool) {
73
+func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool) {
77 74
 	c.lock.Lock()
78 75
 	defer c.lock.Unlock()
79 76
 
80 77
 	if c.lru.Contains(key) {
81 78
 		return true, false
82
-	} else {
83
-		evict := c.lru.Add(key, value)
84
-		return false, evict
85 79
 	}
80
+	evicted = c.lru.Add(key, value)
81
+	return false, evicted
86 82
 }
87 83
 
88 84
 // Remove removes the provided key from the cache.

+ 2
- 2
vendor/github.com/hashicorp/golang-lru/lru_test.go View File

@@ -72,7 +72,7 @@ func TestLRU(t *testing.T) {
72 72
 		if k != v {
73 73
 			t.Fatalf("Evict values not equal (%v!=%v)", k, v)
74 74
 		}
75
-		evictCounter += 1
75
+		evictCounter++
76 76
 	}
77 77
 	l, err := NewWithEvict(128, onEvicted)
78 78
 	if err != nil {
@@ -136,7 +136,7 @@ func TestLRU(t *testing.T) {
136 136
 func TestLRUAdd(t *testing.T) {
137 137
 	evictCounter := 0
138 138
 	onEvicted := func(k interface{}, v interface{}) {
139
-		evictCounter += 1
139
+		evictCounter++
140 140
 	}
141 141
 
142 142
 	l, err := NewWithEvict(1, onEvicted)

+ 9
- 8
vendor/github.com/hashicorp/golang-lru/simplelru/lru.go View File

@@ -36,7 +36,7 @@ func NewLRU(size int, onEvict EvictCallback) (*LRU, error) {
36 36
 	return c, nil
37 37
 }
38 38
 
39
-// Purge is used to completely clear the cache
39
+// Purge is used to completely clear the cache.
40 40
 func (c *LRU) Purge() {
41 41
 	for k, v := range c.items {
42 42
 		if c.onEvict != nil {
@@ -48,7 +48,7 @@ func (c *LRU) Purge() {
48 48
 }
49 49
 
50 50
 // Add adds a value to the cache.  Returns true if an eviction occurred.
51
-func (c *LRU) Add(key, value interface{}) bool {
51
+func (c *LRU) Add(key, value interface{}) (evicted bool) {
52 52
 	// Check for existing item
53 53
 	if ent, ok := c.items[key]; ok {
54 54
 		c.evictList.MoveToFront(ent)
@@ -78,17 +78,18 @@ func (c *LRU) Get(key interface{}) (value interface{}, ok bool) {
78 78
 	return
79 79
 }
80 80
 
81
-// Check if a key is in the cache, without updating the recent-ness
81
+// Contains checks if a key is in the cache, without updating the recent-ness
82 82
 // or deleting it for being stale.
83 83
 func (c *LRU) Contains(key interface{}) (ok bool) {
84 84
 	_, ok = c.items[key]
85 85
 	return ok
86 86
 }
87 87
 
88
-// Returns the key value (or undefined if not found) without updating
88
+// Peek returns the key value (or undefined if not found) without updating
89 89
 // the "recently used"-ness of the key.
90 90
 func (c *LRU) Peek(key interface{}) (value interface{}, ok bool) {
91
-	if ent, ok := c.items[key]; ok {
91
+	var ent *list.Element
92
+	if ent, ok = c.items[key]; ok {
92 93
 		return ent.Value.(*entry).value, true
93 94
 	}
94 95
 	return nil, ok
@@ -96,7 +97,7 @@ func (c *LRU) Peek(key interface{}) (value interface{}, ok bool) {
96 97
 
97 98
 // Remove removes the provided key from the cache, returning if the
98 99
 // key was contained.
99
-func (c *LRU) Remove(key interface{}) bool {
100
+func (c *LRU) Remove(key interface{}) (present bool) {
100 101
 	if ent, ok := c.items[key]; ok {
101 102
 		c.removeElement(ent)
102 103
 		return true
@@ -105,7 +106,7 @@ func (c *LRU) Remove(key interface{}) bool {
105 106
 }
106 107
 
107 108
 // RemoveOldest removes the oldest item from the cache.
108
-func (c *LRU) RemoveOldest() (interface{}, interface{}, bool) {
109
+func (c *LRU) RemoveOldest() (key interface{}, value interface{}, ok bool) {
109 110
 	ent := c.evictList.Back()
110 111
 	if ent != nil {
111 112
 		c.removeElement(ent)
@@ -116,7 +117,7 @@ func (c *LRU) RemoveOldest() (interface{}, interface{}, bool) {
116 117
 }
117 118
 
118 119
 // GetOldest returns the oldest entry
119
-func (c *LRU) GetOldest() (interface{}, interface{}, bool) {
120
+func (c *LRU) GetOldest() (key interface{}, value interface{}, ok bool) {
120 121
 	ent := c.evictList.Back()
121 122
 	if ent != nil {
122 123
 		kv := ent.Value.(*entry)

+ 36
- 0
vendor/github.com/hashicorp/golang-lru/simplelru/lru_interface.go View File

@@ -0,0 +1,36 @@
1
+package simplelru
2
+
3
+// LRUCache is the interface for simple LRU cache.
4
+type LRUCache interface {
5
+	// Adds a value to the cache, returns true if an eviction occurred and
6
+	// updates the "recently used"-ness of the key.
7
+	Add(key, value interface{}) bool
8
+
9
+	// Returns key's value from the cache and
10
+	// updates the "recently used"-ness of the key. #value, isFound
11
+	Get(key interface{}) (value interface{}, ok bool)
12
+
13
+	// Check if a key exsists in cache without updating the recent-ness.
14
+	Contains(key interface{}) (ok bool)
15
+
16
+	// Returns key's value without updating the "recently used"-ness of the key.
17
+	Peek(key interface{}) (value interface{}, ok bool)
18
+
19
+	// Removes a key from the cache.
20
+	Remove(key interface{}) bool
21
+
22
+	// Removes the oldest entry from cache.
23
+	RemoveOldest() (interface{}, interface{}, bool)
24
+
25
+	// Returns the oldest entry from the cache. #key, value, isFound
26
+	GetOldest() (interface{}, interface{}, bool)
27
+
28
+	// Returns a slice of the keys in the cache, from oldest to newest.
29
+	Keys() []interface{}
30
+
31
+	// Returns the number of items in the cache.
32
+	Len() int
33
+
34
+	// Clear all cache entries
35
+	Purge()
36
+}

+ 2
- 2
vendor/github.com/hashicorp/golang-lru/simplelru/lru_test.go View File

@@ -8,7 +8,7 @@ func TestLRU(t *testing.T) {
8 8
 		if k != v {
9 9
 			t.Fatalf("Evict values not equal (%v!=%v)", k, v)
10 10
 		}
11
-		evictCounter += 1
11
+		evictCounter++
12 12
 	}
13 13
 	l, err := NewLRU(128, onEvicted)
14 14
 	if err != nil {
@@ -112,7 +112,7 @@ func TestLRU_GetOldest_RemoveOldest(t *testing.T) {
112 112
 func TestLRU_Add(t *testing.T) {
113 113
 	evictCounter := 0
114 114
 	onEvicted := func(k interface{}, v interface{}) {
115
-		evictCounter += 1
115
+		evictCounter++
116 116
 	}
117 117
 
118 118
 	l, err := NewLRU(1, onEvicted)

+ 21
- 0
vendor/github.com/hashicorp/hcl/.github/ISSUE_TEMPLATE.md View File

@@ -0,0 +1,21 @@
1
+### HCL Template
2
+```hcl
3
+# Place your HCL configuration file here
4
+```
5
+
6
+### Expected behavior
7
+What should have happened?
8
+
9
+### Actual behavior
10
+What actually happened?
11
+
12
+### Steps to reproduce
13
+1.
14
+2.
15
+3.
16
+
17
+### References
18
+Are there any other GitHub issues (open or closed) that should
19
+be linked here? For example:
20
+- GH-1234
21
+- ...

+ 9
- 0
vendor/github.com/hashicorp/hcl/.gitignore View File

@@ -0,0 +1,9 @@
1
+y.output
2
+
3
+# ignore intellij files
4
+.idea
5
+*.iml
6
+*.ipr
7
+*.iws
8
+
9
+*.test

+ 13
- 0
vendor/github.com/hashicorp/hcl/.travis.yml View File

@@ -0,0 +1,13 @@
1
+sudo: false
2
+
3
+language: go
4
+
5
+go:
6
+  - 1.x
7
+  - tip
8
+
9
+branches:
10
+  only:
11
+    - master
12
+
13
+script: make test

+ 354
- 0
vendor/github.com/hashicorp/hcl/LICENSE View File

@@ -0,0 +1,354 @@
1
+Mozilla Public License, version 2.0
2
+
3
+1. Definitions
4
+
5
+1.1. “Contributor”
6
+
7
+     means each individual or legal entity that creates, contributes to the
8
+     creation of, or owns Covered Software.
9
+
10
+1.2. “Contributor Version”
11
+
12
+     means the combination of the Contributions of others (if any) used by a
13
+     Contributor and that particular Contributor’s Contribution.
14
+
15
+1.3. “Contribution”
16
+
17
+     means Covered Software of a particular Contributor.
18
+
19
+1.4. “Covered Software”
20
+
21
+     means Source Code Form to which the initial Contributor has attached the
22
+     notice in Exhibit A, the Executable Form of such Source Code Form, and
23
+     Modifications of such Source Code Form, in each case including portions
24
+     thereof.
25
+
26
+1.5. “Incompatible With Secondary Licenses”
27
+     means
28
+
29
+     a. that the initial Contributor has attached the notice described in
30
+        Exhibit B to the Covered Software; or
31
+
32
+     b. that the Covered Software was made available under the terms of version
33
+        1.1 or earlier of the License, but not also under the terms of a
34
+        Secondary License.
35
+
36
+1.6. “Executable Form”
37
+
38
+     means any form of the work other than Source Code Form.
39
+
40
+1.7. “Larger Work”
41
+
42
+     means a work that combines Covered Software with other material, in a separate
43
+     file or files, that is not Covered Software.
44
+
45
+1.8. “License”
46
+
47
+     means this document.
48
+
49
+1.9. “Licensable”
50
+
51
+     means having the right to grant, to the maximum extent possible, whether at the
52
+     time of the initial grant or subsequently, any and all of the rights conveyed by
53
+     this License.
54
+
55
+1.10. “Modifications”
56
+
57
+     means any of the following:
58
+
59
+     a. any file in Source Code Form that results from an addition to, deletion
60
+        from, or modification of the contents of Covered Software; or
61
+
62
+     b. any new file in Source Code Form that contains any Covered Software.
63
+
64
+1.11. “Patent Claims” of a Contributor
65
+
66
+      means any patent claim(s), including without limitation, method, process,
67
+      and apparatus claims, in any patent Licensable by such Contributor that
68
+      would be infringed, but for the grant of the License, by the making,
69
+      using, selling, offering for sale, having made, import, or transfer of
70
+      either its Contributions or its Contributor Version.
71
+
72
+1.12. “Secondary License”
73
+
74
+      means either the GNU General Public License, Version 2.0, the GNU Lesser
75
+      General Public License, Version 2.1, the GNU Affero General Public
76
+      License, Version 3.0, or any later versions of those licenses.
77
+
78
+1.13. “Source Code Form”
79
+
80
+      means the form of the work preferred for making modifications.
81
+
82
+1.14. “You” (or “Your”)
83
+
84
+      means an individual or a legal entity exercising rights under this
85
+      License. For legal entities, “You” includes any entity that controls, is
86
+      controlled by, or is under common control with You. For purposes of this
87
+      definition, “control” means (a) the power, direct or indirect, to cause
88
+      the direction or management of such entity, whether by contract or
89
+      otherwise, or (b) ownership of more than fifty percent (50%) of the
90
+      outstanding shares or beneficial ownership of such entity.
91
+
92
+
93
+2. License Grants and Conditions
94
+
95
+2.1. Grants
96
+
97
+     Each Contributor hereby grants You a world-wide, royalty-free,
98
+     non-exclusive license:
99
+
100
+     a. under intellectual property rights (other than patent or trademark)
101
+        Licensable by such Contributor to use, reproduce, make available,
102
+        modify, display, perform, distribute, and otherwise exploit its
103
+        Contributions, either on an unmodified basis, with Modifications, or as
104
+        part of a Larger Work; and
105
+
106
+     b. under Patent Claims of such Contributor to make, use, sell, offer for
107
+        sale, have made, import, and otherwise transfer either its Contributions
108
+        or its Contributor Version.
109
+
110
+2.2. Effective Date
111
+
112
+     The licenses granted in Section 2.1 with respect to any Contribution become
113
+     effective for each Contribution on the date the Contributor first distributes
114
+     such Contribution.
115
+
116
+2.3. Limitations on Grant Scope
117
+
118
+     The licenses granted in this Section 2 are the only rights granted under this
119
+     License. No additional rights or licenses will be implied from the distribution
120
+     or licensing of Covered Software under this License. Notwithstanding Section
121
+     2.1(b) above, no patent license is granted by a Contributor:
122
+
123
+     a. for any code that a Contributor has removed from Covered Software; or
124
+
125
+     b. for infringements caused by: (i) Your and any other third party’s
126
+        modifications of Covered Software, or (ii) the combination of its
127
+        Contributions with other software (except as part of its Contributor
128
+        Version); or
129
+
130
+     c. under Patent Claims infringed by Covered Software in the absence of its
131
+        Contributions.
132
+
133
+     This License does not grant any rights in the trademarks, service marks, or
134
+     logos of any Contributor (except as may be necessary to comply with the
135
+     notice requirements in Section 3.4).
136
+
137
+2.4. Subsequent Licenses
138
+
139
+     No Contributor makes additional grants as a result of Your choice to
140
+     distribute the Covered Software under a subsequent version of this License
141
+     (see Section 10.2) or under the terms of a Secondary License (if permitted
142
+     under the terms of Section 3.3).
143
+
144
+2.5. Representation
145
+
146
+     Each Contributor represents that the Contributor believes its Contributions
147
+     are its original creation(s) or it has sufficient rights to grant the
148
+     rights to its Contributions conveyed by this License.
149
+
150
+2.6. Fair Use
151
+
152
+     This License is not intended to limit any rights You have under applicable
153
+     copyright doctrines of fair use, fair dealing, or other equivalents.
154
+
155
+2.7. Conditions
156
+
157
+     Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
158
+     Section 2.1.
159
+
160
+
161
+3. Responsibilities
162
+
163
+3.1. Distribution of Source Form
164
+
165
+     All distribution of Covered Software in Source Code Form, including any
166
+     Modifications that You create or to which You contribute, must be under the
167
+     terms of this License. You must inform recipients that the Source Code Form
168
+     of the Covered Software is governed by the terms of this License, and how
169
+     they can obtain a copy of this License. You may not attempt to alter or
170
+     restrict the recipients’ rights in the Source Code Form.
171
+
172
+3.2. Distribution of Executable Form
173
+
174
+     If You distribute Covered Software in Executable Form then:
175
+
176
+     a. such Covered Software must also be made available in Source Code Form,
177
+        as described in Section 3.1, and You must inform recipients of the
178
+        Executable Form how they can obtain a copy of such Source Code Form by
179
+        reasonable means in a timely manner, at a charge no more than the cost
180
+        of distribution to the recipient; and
181
+
182
+     b. You may distribute such Executable Form under the terms of this License,
183
+        or sublicense it under different terms, provided that the license for
184
+        the Executable Form does not attempt to limit or alter the recipients’
185
+        rights in the Source Code Form under this License.
186
+
187
+3.3. Distribution of a Larger Work
188
+
189
+     You may create and distribute a Larger Work under terms of Your choice,
190
+     provided that You also comply with the requirements of this License for the
191
+     Covered Software. If the Larger Work is a combination of Covered Software
192
+     with a work governed by one or more Secondary Licenses, and the Covered
193
+     Software is not Incompatible With Secondary Licenses, this License permits
194
+     You to additionally distribute such Covered Software under the terms of
195
+     such Secondary License(s), so that the recipient of the Larger Work may, at
196
+     their option, further distribute the Covered Software under the terms of
197
+     either this License or such Secondary License(s).
198
+
199
+3.4. Notices
200
+
201
+     You may not remove or alter the substance of any license notices (including
202
+     copyright notices, patent notices, disclaimers of warranty, or limitations
203
+     of liability) contained within the Source Code Form of the Covered
204
+     Software, except that You may alter any license notices to the extent
205
+     required to remedy known factual inaccuracies.
206
+
207
+3.5. Application of Additional Terms
208
+
209
+     You may choose to offer, and to charge a fee for, warranty, support,
210
+     indemnity or liability obligations to one or more recipients of Covered
211
+     Software. However, You may do so only on Your own behalf, and not on behalf
212
+     of any Contributor. You must make it absolutely clear that any such
213
+     warranty, support, indemnity, or liability obligation is offered by You
214
+     alone, and You hereby agree to indemnify every Contributor for any
215
+     liability incurred by such Contributor as a result of warranty, support,
216
+     indemnity or liability terms You offer. You may include additional
217
+     disclaimers of warranty and limitations of liability specific to any
218
+     jurisdiction.
219
+
220
+4. Inability to Comply Due to Statute or Regulation
221
+
222
+   If it is impossible for You to comply with any of the terms of this License
223
+   with respect to some or all of the Covered Software due to statute, judicial
224
+   order, or regulation then You must: (a) comply with the terms of this License
225
+   to the maximum extent possible; and (b) describe the limitations and the code
226
+   they affect. Such description must be placed in a text file included with all
227
+   distributions of the Covered Software under this License. Except to the
228
+   extent prohibited by statute or regulation, such description must be
229
+   sufficiently detailed for a recipient of ordinary skill to be able to
230
+   understand it.
231
+
232
+5. Termination
233
+
234
+5.1. The rights granted under this License will terminate automatically if You
235
+     fail to comply with any of its terms. However, if You become compliant,
236
+     then the rights granted under this License from a particular Contributor
237
+     are reinstated (a) provisionally, unless and until such Contributor
238
+     explicitly and finally terminates Your grants, and (b) on an ongoing basis,
239
+     if such Contributor fails to notify You of the non-compliance by some
240
+     reasonable means prior to 60 days after You have come back into compliance.
241
+     Moreover, Your grants from a particular Contributor are reinstated on an
242
+     ongoing basis if such Contributor notifies You of the non-compliance by
243
+     some reasonable means, this is the first time You have received notice of
244
+     non-compliance with this License from such Contributor, and You become
245
+     compliant prior to 30 days after Your receipt of the notice.
246
+
247
+5.2. If You initiate litigation against any entity by asserting a patent
248
+     infringement claim (excluding declaratory judgment actions, counter-claims,
249
+     and cross-claims) alleging that a Contributor Version directly or
250
+     indirectly infringes any patent, then the rights granted to You by any and
251
+     all Contributors for the Covered Software under Section 2.1 of this License
252
+     shall terminate.
253
+
254
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
255
+     license agreements (excluding distributors and resellers) which have been
256
+     validly granted by You or Your distributors under this License prior to
257
+     termination shall survive termination.
258
+
259
+6. Disclaimer of Warranty
260
+
261
+   Covered Software is provided under this License on an “as is” basis, without
262
+   warranty of any kind, either expressed, implied, or statutory, including,
263
+   without limitation, warranties that the Covered Software is free of defects,
264
+   merchantable, fit for a particular purpose or non-infringing. The entire
265
+   risk as to the quality and performance of the Covered Software is with You.
266
+   Should any Covered Software prove defective in any respect, You (not any
267
+   Contributor) assume the cost of any necessary servicing, repair, or
268
+   correction. This disclaimer of warranty constitutes an essential part of this
269
+   License. No use of  any Covered Software is authorized under this License
270
+   except under this disclaimer.
271
+
272
+7. Limitation of Liability
273
+
274
+   Under no circumstances and under no legal theory, whether tort (including
275
+   negligence), contract, or otherwise, shall any Contributor, or anyone who
276
+   distributes Covered Software as permitted above, be liable to You for any
277
+   direct, indirect, special, incidental, or consequential damages of any
278
+   character including, without limitation, damages for lost profits, loss of
279
+   goodwill, work stoppage, computer failure or malfunction, or any and all
280
+   other commercial damages or losses, even if such party shall have been
281
+   informed of the possibility of such damages. This limitation of liability
282
+   shall not apply to liability for death or personal injury resulting from such
283
+   party’s negligence to the extent applicable law prohibits such limitation.
284
+   Some jurisdictions do not allow the exclusion or limitation of incidental or
285
+   consequential damages, so this exclusion and limitation may not apply to You.
286
+
287
+8. Litigation
288
+
289
+   Any litigation relating to this License may be brought only in the courts of
290
+   a jurisdiction where the defendant maintains its principal place of business
291
+   and such litigation shall be governed by laws of that jurisdiction, without
292
+   reference to its conflict-of-law provisions. Nothing in this Section shall
293
+   prevent a party’s ability to bring cross-claims or counter-claims.
294
+
295
+9. Miscellaneous
296
+
297
+   This License represents the complete agreement concerning the subject matter
298
+   hereof. If any provision of this License is held to be unenforceable, such
299
+   provision shall be reformed only to the extent necessary to make it
300
+   enforceable. Any law or regulation which provides that the language of a
301
+   contract shall be construed against the drafter shall not be used to construe
302
+   this License against a Contributor.
303
+
304
+
305
+10. Versions of the License
306
+
307
+10.1. New Versions
308
+
309
+      Mozilla Foundation is the license steward. Except as provided in Section
310
+      10.3, no one other than the license steward has the right to modify or
311
+      publish new versions of this License. Each version will be given a
312
+      distinguishing version number.
313
+
314
+10.2. Effect of New Versions
315
+
316
+      You may distribute the Covered Software under the terms of the version of
317
+      the License under which You originally received the Covered Software, or
318
+      under the terms of any subsequent version published by the license
319
+      steward.
320
+
321
+10.3. Modified Versions
322
+
323
+      If you create software not governed by this License, and you want to
324
+      create a new license for such software, you may create and use a modified
325
+      version of this License if you rename the license and remove any
326
+      references to the name of the license steward (except to note that such
327
+      modified license differs from this License).
328
+
329
+10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
330
+      If You choose to distribute Source Code Form that is Incompatible With
331
+      Secondary Licenses under the terms of this version of the License, the
332
+      notice described in Exhibit B of this License must be attached.
333
+
334
+Exhibit A - Source Code Form License Notice
335
+
336
+      This Source Code Form is subject to the
337
+      terms of the Mozilla Public License, v.
338
+      2.0. If a copy of the MPL was not
339
+      distributed with this file, You can
340
+      obtain one at
341
+      http://mozilla.org/MPL/2.0/.
342
+
343
+If it is not possible or desirable to put the notice in a particular file, then
344
+You may include the notice in a location (such as a LICENSE file in a relevant
345
+directory) where a recipient would be likely to look for such a notice.
346
+
347
+You may add additional accurate notices of copyright ownership.
348
+
349
+Exhibit B - “Incompatible With Secondary Licenses” Notice
350
+
351
+      This Source Code Form is “Incompatible
352
+      With Secondary Licenses”, as defined by
353
+      the Mozilla Public License, v. 2.0.
354
+

+ 18
- 0
vendor/github.com/hashicorp/hcl/Makefile View File

@@ -0,0 +1,18 @@
1
+TEST?=./...
2
+
3
+default: test
4
+
5
+fmt: generate
6
+	go fmt ./...
7
+
8
+test: generate
9
+	go get -t ./...
10
+	go test $(TEST) $(TESTARGS)
11
+
12
+generate:
13
+	go generate ./...
14
+
15
+updatedeps:
16
+	go get -u golang.org/x/tools/cmd/stringer
17
+
18
+.PHONY: default generate test updatedeps

+ 125
- 0
vendor/github.com/hashicorp/hcl/README.md View File

@@ -0,0 +1,125 @@
1
+# HCL
2
+
3
+[![GoDoc](https://godoc.org/github.com/hashicorp/hcl?status.png)](https://godoc.org/github.com/hashicorp/hcl) [![Build Status](https://travis-ci.org/hashicorp/hcl.svg?branch=master)](https://travis-ci.org/hashicorp/hcl)
4
+
5
+HCL (HashiCorp Configuration Language) is a configuration language built
6
+by HashiCorp. The goal of HCL is to build a structured configuration language
7
+that is both human and machine friendly for use with command-line tools, but
8
+specifically targeted towards DevOps tools, servers, etc.
9
+
10
+HCL is also fully JSON compatible. That is, JSON can be used as completely
11
+valid input to a system expecting HCL. This helps makes systems
12
+interoperable with other systems.
13
+
14
+HCL is heavily inspired by
15
+[libucl](https://github.com/vstakhov/libucl),
16
+nginx configuration, and others similar.
17
+
18
+## Why?
19
+
20
+A common question when viewing HCL is to ask the question: why not
21
+JSON, YAML, etc.?
22
+
23
+Prior to HCL, the tools we built at [HashiCorp](http://www.hashicorp.com)
24
+used a variety of configuration languages from full programming languages
25
+such as Ruby to complete data structure languages such as JSON. What we
26
+learned is that some people wanted human-friendly configuration languages
27
+and some people wanted machine-friendly languages.
28
+
29
+JSON fits a nice balance in this, but is fairly verbose and most
30
+importantly doesn't support comments. With YAML, we found that beginners
31
+had a really hard time determining what the actual structure was, and
32
+ended up guessing more often than not whether to use a hyphen, colon, etc.
33
+in order to represent some configuration key.
34
+
35
+Full programming languages such as Ruby enable complex behavior
36
+a configuration language shouldn't usually allow, and also forces
37
+people to learn some set of Ruby.
38
+
39
+Because of this, we decided to create our own configuration language
40
+that is JSON-compatible. Our configuration language (HCL) is designed
41
+to be written and modified by humans. The API for HCL allows JSON
42
+as an input so that it is also machine-friendly (machines can generate
43
+JSON instead of trying to generate HCL).
44
+
45
+Our goal with HCL is not to alienate other configuration languages.
46
+It is instead to provide HCL as a specialized language for our tools,
47
+and JSON as the interoperability layer.
48
+
49
+## Syntax
50
+
51
+For a complete grammar, please see the parser itself. A high-level overview
52
+of the syntax and grammar is listed here.
53
+
54
+  * Single line comments start with `#` or `//`
55
+
56
+  * Multi-line comments are wrapped in `/*` and `*/`. Nested block comments
57
+    are not allowed. A multi-line comment (also known as a block comment)
58
+    terminates at the first `*/` found.
59
+
60
+  * Values are assigned with the syntax `key = value` (whitespace doesn't
61
+    matter). The value can be any primitive: a string, number, boolean,
62
+    object, or list.
63
+
64
+  * Strings are double-quoted and can contain any UTF-8 characters.
65
+    Example: `"Hello, World"`
66
+
67
+  * Multi-line strings start with `<<EOF` at the end of a line, and end
68
+    with `EOF` on its own line ([here documents](https://en.wikipedia.org/wiki/Here_document)).
69
+    Any text may be used in place of `EOF`. Example:
70
+```
71
+<<FOO
72
+hello
73
+world
74
+FOO
75
+```
76
+
77
+  * Numbers are assumed to be base 10. If you prefix a number with 0x,
78
+    it is treated as a hexadecimal. If it is prefixed with 0, it is
79
+    treated as an octal. Numbers can be in scientific notation: "1e10".
80
+
81
+  * Boolean values: `true`, `false`
82
+
83
+  * Arrays can be made by wrapping it in `[]`. Example:
84
+    `["foo", "bar", 42]`. Arrays can contain primitives,
85
+    other arrays, and objects. As an alternative, lists
86
+    of objects can be created with repeated blocks, using
87
+    this structure:
88
+
89
+    ```hcl
90
+    service {
91
+        key = "value"
92
+    }
93
+
94
+    service {
95
+        key = "value"
96
+    }
97
+    ```
98
+
99
+Objects and nested objects are created using the structure shown below:
100
+
101
+```
102
+variable "ami" {
103
+    description = "the AMI to use"
104
+}
105
+```
106
+This would be equivalent to the following json:
107
+``` json
108
+{
109
+  "variable": {
110
+      "ami": {
111
+          "description": "the AMI to use"
112
+        }
113
+    }
114
+}
115
+```
116
+
117
+## Thanks
118
+
119
+Thanks to:
120
+
121
+  * [@vstakhov](https://github.com/vstakhov) - The original libucl parser
122
+    and syntax that HCL was based off of.
123
+
124
+  * [@fatih](https://github.com/fatih) - The rewritten HCL parser
125
+    in pure Go (no goyacc) and support for a printer.

+ 19
- 0
vendor/github.com/hashicorp/hcl/appveyor.yml View File

@@ -0,0 +1,19 @@
1
+version: "build-{branch}-{build}"
2
+image: Visual Studio 2015
3
+clone_folder: c:\gopath\src\github.com\hashicorp\hcl
4
+environment:
5
+  GOPATH: c:\gopath
6
+init:
7
+  - git config --global core.autocrlf false
8
+install:
9
+- cmd: >-
10
+    echo %Path%
11
+
12
+    go version
13
+
14
+    go env
15
+
16
+    go get -t ./...
17
+
18
+build_script:
19
+- cmd: go test -v ./...

+ 729
- 0
vendor/github.com/hashicorp/hcl/decoder.go View File

@@ -0,0 +1,729 @@
1
+package hcl
2
+
3
+import (
4
+	"errors"
5
+	"fmt"
6
+	"reflect"
7
+	"sort"
8
+	"strconv"
9
+	"strings"
10
+
11
+	"github.com/hashicorp/hcl/hcl/ast"
12
+	"github.com/hashicorp/hcl/hcl/parser"
13
+	"github.com/hashicorp/hcl/hcl/token"
14
+)
15
+
16
+// This is the tag to use with structures to have settings for HCL
17
+const tagName = "hcl"
18
+
19
+var (
20
+	// nodeType holds a reference to the type of ast.Node
21
+	nodeType reflect.Type = findNodeType()
22
+)
23
+
24
+// Unmarshal accepts a byte slice as input and writes the
25
+// data to the value pointed to by v.
26
+func Unmarshal(bs []byte, v interface{}) error {
27
+	root, err := parse(bs)
28
+	if err != nil {
29
+		return err
30
+	}
31
+
32
+	return DecodeObject(v, root)
33
+}
34
+
35
+// Decode reads the given input and decodes it into the structure
36
+// given by `out`.
37
+func Decode(out interface{}, in string) error {
38
+	obj, err := Parse(in)
39
+	if err != nil {
40
+		return err
41
+	}
42
+
43
+	return DecodeObject(out, obj)
44
+}
45
+
46
+// DecodeObject is a lower-level version of Decode. It decodes a
47
+// raw Object into the given output.
48
+func DecodeObject(out interface{}, n ast.Node) error {
49
+	val := reflect.ValueOf(out)
50
+	if val.Kind() != reflect.Ptr {
51
+		return errors.New("result must be a pointer")
52
+	}
53
+
54
+	// If we have the file, we really decode the root node
55
+	if f, ok := n.(*ast.File); ok {
56
+		n = f.Node
57
+	}
58
+
59
+	var d decoder
60
+	return d.decode("root", n, val.Elem())
61
+}
62
+
63
+type decoder struct {
64
+	stack []reflect.Kind
65
+}
66
+
67
+func (d *decoder) decode(name string, node ast.Node, result reflect.Value) error {
68
+	k := result
69
+
70
+	// If we have an interface with a valid value, we use that
71
+	// for the check.
72
+	if result.Kind() == reflect.Interface {
73
+		elem := result.Elem()
74
+		if elem.IsValid() {
75
+			k = elem
76
+		}
77
+	}
78
+
79
+	// Push current onto stack unless it is an interface.
80
+	if k.Kind() != reflect.Interface {
81
+		d.stack = append(d.stack, k.Kind())
82
+
83
+		// Schedule a pop
84
+		defer func() {
85
+			d.stack = d.stack[:len(d.stack)-1]
86
+		}()
87
+	}
88
+
89
+	switch k.Kind() {
90
+	case reflect.Bool:
91
+		return d.decodeBool(name, node, result)
92
+	case reflect.Float32, reflect.Float64:
93
+		return d.decodeFloat(name, node, result)
94
+	case reflect.Int, reflect.Int32, reflect.Int64:
95
+		return d.decodeInt(name, node, result)
96
+	case reflect.Interface:
97
+		// When we see an interface, we make our own thing
98
+		return d.decodeInterface(name, node, result)
99
+	case reflect.Map:
100
+		return d.decodeMap(name, node, result)
101
+	case reflect.Ptr:
102
+		return d.decodePtr(name, node, result)
103
+	case reflect.Slice:
104
+		return d.decodeSlice(name, node, result)
105
+	case reflect.String:
106
+		return d.decodeString(name, node, result)
107
+	case reflect.Struct:
108
+		return d.decodeStruct(name, node, result)
109
+	default:
110
+		return &parser.PosError{
111
+			Pos: node.Pos(),
112
+			Err: fmt.Errorf("%s: unknown kind to decode into: %s", name, k.Kind()),
113
+		}
114
+	}
115
+}
116
+
117
+func (d *decoder) decodeBool(name string, node ast.Node, result reflect.Value) error {
118
+	switch n := node.(type) {
119
+	case *ast.LiteralType:
120
+		if n.Token.Type == token.BOOL {
121
+			v, err := strconv.ParseBool(n.Token.Text)
122
+			if err != nil {
123
+				return err
124
+			}
125
+
126
+			result.Set(reflect.ValueOf(v))
127
+			return nil
128
+		}
129
+	}
130
+
131
+	return &parser.PosError{
132
+		Pos: node.Pos(),
133
+		Err: fmt.Errorf("%s: unknown type %T", name, node),
134
+	}
135
+}
136
+
137
+func (d *decoder) decodeFloat(name string, node ast.Node, result reflect.Value) error {
138
+	switch n := node.(type) {
139
+	case *ast.LiteralType:
140
+		if n.Token.Type == token.FLOAT || n.Token.Type == token.NUMBER {
141
+			v, err := strconv.ParseFloat(n.Token.Text, 64)
142
+			if err != nil {
143
+				return err
144
+			}
145
+
146
+			result.Set(reflect.ValueOf(v).Convert(result.Type()))
147
+			return nil
148
+		}
149
+	}
150
+
151
+	return &parser.PosError{
152
+		Pos: node.Pos(),
153
+		Err: fmt.Errorf("%s: unknown type %T", name, node),
154
+	}
155
+}
156
+
157
+func (d *decoder) decodeInt(name string, node ast.Node, result reflect.Value) error {
158
+	switch n := node.(type) {
159
+	case *ast.LiteralType:
160
+		switch n.Token.Type {
161
+		case token.NUMBER:
162
+			v, err := strconv.ParseInt(n.Token.Text, 0, 0)
163
+			if err != nil {
164
+				return err
165
+			}
166
+
167
+			if result.Kind() == reflect.Interface {
168
+				result.Set(reflect.ValueOf(int(v)))
169
+			} else {
170
+				result.SetInt(v)
171
+			}
172
+			return nil
173
+		case token.STRING:
174
+			v, err := strconv.ParseInt(n.Token.Value().(string), 0, 0)
175
+			if err != nil {
176
+				return err
177
+			}
178
+
179
+			if result.Kind() == reflect.Interface {
180
+				result.Set(reflect.ValueOf(int(v)))
181
+			} else {
182
+				result.SetInt(v)
183
+			}
184
+			return nil
185
+		}
186
+	}
187
+
188
+	return &parser.PosError{
189
+		Pos: node.Pos(),
190
+		Err: fmt.Errorf("%s: unknown type %T", name, node),
191
+	}
192
+}
193
+
194
+func (d *decoder) decodeInterface(name string, node ast.Node, result reflect.Value) error {
195
+	// When we see an ast.Node, we retain the value to enable deferred decoding.
196
+	// Very useful in situations where we want to preserve ast.Node information
197
+	// like Pos
198
+	if result.Type() == nodeType && result.CanSet() {
199
+		result.Set(reflect.ValueOf(node))
200
+		return nil
201
+	}
202
+
203
+	var set reflect.Value
204
+	redecode := true
205
+
206
+	// For testing types, ObjectType should just be treated as a list. We
207
+	// set this to a temporary var because we want to pass in the real node.
208
+	testNode := node
209
+	if ot, ok := node.(*ast.ObjectType); ok {
210
+		testNode = ot.List
211
+	}
212
+
213
+	switch n := testNode.(type) {
214
+	case *ast.ObjectList:
215
+		// If we're at the root or we're directly within a slice, then we
216
+		// decode objects into map[string]interface{}, otherwise we decode
217
+		// them into lists.
218
+		if len(d.stack) == 0 || d.stack[len(d.stack)-1] == reflect.Slice {
219
+			var temp map[string]interface{}
220
+			tempVal := reflect.ValueOf(temp)
221
+			result := reflect.MakeMap(
222
+				reflect.MapOf(
223
+					reflect.TypeOf(""),
224
+					tempVal.Type().Elem()))
225
+
226
+			set = result
227
+		} else {
228
+			var temp []map[string]interface{}
229
+			tempVal := reflect.ValueOf(temp)
230
+			result := reflect.MakeSlice(
231
+				reflect.SliceOf(tempVal.Type().Elem()), 0, len(n.Items))
232
+			set = result
233
+		}
234
+	case *ast.ObjectType:
235
+		// If we're at the root or we're directly within a slice, then we
236
+		// decode objects into map[string]interface{}, otherwise we decode
237
+		// them into lists.
238
+		if len(d.stack) == 0 || d.stack[len(d.stack)-1] == reflect.Slice {
239
+			var temp map[string]interface{}
240
+			tempVal := reflect.ValueOf(temp)
241
+			result := reflect.MakeMap(
242
+				reflect.MapOf(
243
+					reflect.TypeOf(""),
244
+					tempVal.Type().Elem()))
245
+
246
+			set = result
247
+		} else {
248
+			var temp []map[string]interface{}
249
+			tempVal := reflect.ValueOf(temp)
250
+			result := reflect.MakeSlice(
251
+				reflect.SliceOf(tempVal.Type().Elem()), 0, 1)
252
+			set = result
253
+		}
254
+	case *ast.ListType:
255
+		var temp []interface{}
256
+		tempVal := reflect.ValueOf(temp)
257
+		result := reflect.MakeSlice(
258
+			reflect.SliceOf(tempVal.Type().Elem()), 0, 0)
259
+		set = result
260
+	case *ast.LiteralType:
261
+		switch n.Token.Type {
262
+		case token.BOOL:
263
+			var result bool
264
+			set = reflect.Indirect(reflect.New(reflect.TypeOf(result)))
265
+		case token.FLOAT:
266
+			var result float64
267
+			set = reflect.Indirect(reflect.New(reflect.TypeOf(result)))
268
+		case token.NUMBER:
269
+			var result int
270
+			set = reflect.Indirect(reflect.New(reflect.TypeOf(result)))
271
+		case token.STRING, token.HEREDOC:
272
+			set = reflect.Indirect(reflect.New(reflect.TypeOf("")))
273
+		default:
274
+			return &parser.PosError{
275
+				Pos: node.Pos(),
276
+				Err: fmt.Errorf("%s: cannot decode into interface: %T", name, node),
277
+			}
278
+		}
279
+	default:
280
+		return fmt.Errorf(
281
+			"%s: cannot decode into interface: %T",
282
+			name, node)
283
+	}
284
+
285
+	// Set the result to what its supposed to be, then reset
286
+	// result so we don't reflect into this method anymore.
287
+	result.Set(set)
288
+
289
+	if redecode {
290
+		// Revisit the node so that we can use the newly instantiated
291
+		// thing and populate it.
292
+		if err := d.decode(name, node, result); err != nil {
293
+			return err
294
+		}
295
+	}
296
+
297
+	return nil
298
+}
299
+
300
+func (d *decoder) decodeMap(name string, node ast.Node, result reflect.Value) error {
301
+	if item, ok := node.(*ast.ObjectItem); ok {
302
+		node = &ast.ObjectList{Items: []*ast.ObjectItem{item}}
303
+	}
304
+
305
+	if ot, ok := node.(*ast.ObjectType); ok {
306
+		node = ot.List
307
+	}
308
+
309
+	n, ok := node.(*ast.ObjectList)
310
+	if !ok {
311
+		return &parser.PosError{
312
+			Pos: node.Pos(),
313
+			Err: fmt.Errorf("%s: not an object type for map (%T)", name, node),
314
+		}
315
+	}
316
+
317
+	// If we have an interface, then we can address the interface,
318
+	// but not the slice itself, so get the element but set the interface
319
+	set := result
320
+	if result.Kind() == reflect.Interface {
321
+		result = result.Elem()
322
+	}
323
+
324
+	resultType := result.Type()
325
+	resultElemType := resultType.Elem()
326
+	resultKeyType := resultType.Key()
327
+	if resultKeyType.Kind() != reflect.String {
328
+		return &parser.PosError{
329
+			Pos: node.Pos(),
330
+			Err: fmt.Errorf("%s: map must have string keys", name),
331
+		}
332
+	}
333
+
334
+	// Make a map if it is nil
335
+	resultMap := result
336
+	if result.IsNil() {
337
+		resultMap = reflect.MakeMap(
338
+			reflect.MapOf(resultKeyType, resultElemType))
339
+	}
340
+
341
+	// Go through each element and decode it.
342
+	done := make(map[string]struct{})
343
+	for _, item := range n.Items {
344
+		if item.Val == nil {
345
+			continue
346
+		}
347
+
348
+		// github.com/hashicorp/terraform/issue/5740
349
+		if len(item.Keys) == 0 {
350
+			return &parser.PosError{
351
+				Pos: node.Pos(),
352
+				Err: fmt.Errorf("%s: map must have string keys", name),
353
+			}
354
+		}
355
+
356
+		// Get the key we're dealing with, which is the first item
357
+		keyStr := item.Keys[0].Token.Value().(string)
358
+
359
+		// If we've already processed this key, then ignore it
360
+		if _, ok := done[keyStr]; ok {
361
+			continue
362
+		}
363
+
364
+		// Determine the value. If we have more than one key, then we
365
+		// get the objectlist of only these keys.
366
+		itemVal := item.Val
367
+		if len(item.Keys) > 1 {
368
+			itemVal = n.Filter(keyStr)
369
+			done[keyStr] = struct{}{}
370
+		}
371
+
372
+		// Make the field name
373
+		fieldName := fmt.Sprintf("%s.%s", name, keyStr)
374
+
375
+		// Get the key/value as reflection values
376
+		key := reflect.ValueOf(keyStr)
377
+		val := reflect.Indirect(reflect.New(resultElemType))
378
+
379
+		// If we have a pre-existing value in the map, use that
380
+		oldVal := resultMap.MapIndex(key)
381
+		if oldVal.IsValid() {
382
+			val.Set(oldVal)
383
+		}
384
+
385
+		// Decode!
386
+		if err := d.decode(fieldName, itemVal, val); err != nil {
387
+			return err
388
+		}
389
+
390
+		// Set the value on the map
391
+		resultMap.SetMapIndex(key, val)
392
+	}
393
+
394
+	// Set the final map if we can
395
+	set.Set(resultMap)
396
+	return nil
397
+}
398
+
399
+func (d *decoder) decodePtr(name string, node ast.Node, result reflect.Value) error {
400
+	// Create an element of the concrete (non pointer) type and decode
401
+	// into that. Then set the value of the pointer to this type.
402
+	resultType := result.Type()
403
+	resultElemType := resultType.Elem()
404
+	val := reflect.New(resultElemType)
405
+	if err := d.decode(name, node, reflect.Indirect(val)); err != nil {
406
+		return err
407
+	}
408
+
409
+	result.Set(val)
410
+	return nil
411
+}
412
+
413
+func (d *decoder) decodeSlice(name string, node ast.Node, result reflect.Value) error {
414
+	// If we have an interface, then we can address the interface,
415
+	// but not the slice itself, so get the element but set the interface
416
+	set := result
417
+	if result.Kind() == reflect.Interface {
418
+		result = result.Elem()
419
+	}
420
+	// Create the slice if it isn't nil
421
+	resultType := result.Type()
422
+	resultElemType := resultType.Elem()
423
+	if result.IsNil() {
424
+		resultSliceType := reflect.SliceOf(resultElemType)
425
+		result = reflect.MakeSlice(
426
+			resultSliceType, 0, 0)
427
+	}
428
+
429
+	// Figure out the items we'll be copying into the slice
430
+	var items []ast.Node
431
+	switch n := node.(type) {
432
+	case *ast.ObjectList:
433
+		items = make([]ast.Node, len(n.Items))
434
+		for i, item := range n.Items {
435
+			items[i] = item
436
+		}
437
+	case *ast.ObjectType:
438
+		items = []ast.Node{n}
439
+	case *ast.ListType:
440
+		items = n.List
441
+	default:
442
+		return &parser.PosError{
443
+			Pos: node.Pos(),
444
+			Err: fmt.Errorf("unknown slice type: %T", node),
445
+		}
446
+	}
447
+
448
+	for i, item := range items {
449
+		fieldName := fmt.Sprintf("%s[%d]", name, i)
450
+
451
+		// Decode
452
+		val := reflect.Indirect(reflect.New(resultElemType))
453
+
454
+		// if item is an object that was decoded from ambiguous JSON and
455
+		// flattened, make sure it's expanded if it needs to decode into a
456
+		// defined structure.
457
+		item := expandObject(item, val)
458
+
459
+		if err := d.decode(fieldName, item, val); err != nil {
460
+			return err
461
+		}
462
+
463
+		// Append it onto the slice
464
+		result = reflect.Append(result, val)
465
+	}
466
+
467
+	set.Set(result)
468
+	return nil
469
+}
470
+
471
+// expandObject detects if an ambiguous JSON object was flattened to a List which
472
+// should be decoded into a struct, and expands the ast to properly deocode.
473
+func expandObject(node ast.Node, result reflect.Value) ast.Node {
474
+	item, ok := node.(*ast.ObjectItem)
475
+	if !ok {
476
+		return node
477
+	}
478
+
479
+	elemType := result.Type()
480
+
481
+	// our target type must be a struct
482
+	switch elemType.Kind() {
483
+	case reflect.Ptr:
484
+		switch elemType.Elem().Kind() {
485
+		case reflect.Struct:
486
+			//OK
487
+		default:
488
+			return node
489
+		}
490
+	case reflect.Struct:
491
+		//OK
492
+	default:
493
+		return node
494
+	}
495
+
496
+	// A list value will have a key and field name. If it had more fields,
497
+	// it wouldn't have been flattened.
498
+	if len(item.Keys) != 2 {
499
+		return node
500
+	}
501
+
502
+	keyToken := item.Keys[0].Token
503
+	item.Keys = item.Keys[1:]
504
+
505
+	// we need to un-flatten the ast enough to decode
506
+	newNode := &ast.ObjectItem{
507
+		Keys: []*ast.ObjectKey{
508
+			&ast.ObjectKey{
509
+				Token: keyToken,
510
+			},
511
+		},
512
+		Val: &ast.ObjectType{
513
+			List: &ast.ObjectList{
514
+				Items: []*ast.ObjectItem{item},
515
+			},
516
+		},
517
+	}
518
+
519
+	return newNode
520
+}
521
+
522
+func (d *decoder) decodeString(name string, node ast.Node, result reflect.Value) error {
523
+	switch n := node.(type) {
524
+	case *ast.LiteralType:
525
+		switch n.Token.Type {
526
+		case token.NUMBER:
527
+			result.Set(reflect.ValueOf(n.Token.Text).Convert(result.Type()))
528
+			return nil
529
+		case token.STRING, token.HEREDOC:
530
+			result.Set(reflect.ValueOf(n.Token.Value()).Convert(result.Type()))
531
+			return nil
532
+		}
533
+	}
534
+
535
+	return &parser.PosError{
536
+		Pos: node.Pos(),
537
+		Err: fmt.Errorf("%s: unknown type for string %T", name, node),
538
+	}
539
+}
540
+
541
+func (d *decoder) decodeStruct(name string, node ast.Node, result reflect.Value) error {
542
+	var item *ast.ObjectItem
543
+	if it, ok := node.(*ast.ObjectItem); ok {
544
+		item = it
545
+		node = it.Val
546
+	}
547
+
548
+	if ot, ok := node.(*ast.ObjectType); ok {
549
+		node = ot.List
550
+	}
551
+
552
+	// Handle the special case where the object itself is a literal. Previously
553
+	// the yacc parser would always ensure top-level elements were arrays. The new
554
+	// parser does not make the same guarantees, thus we need to convert any
555
+	// top-level literal elements into a list.
556
+	if _, ok := node.(*ast.LiteralType); ok && item != nil {
557
+		node = &ast.ObjectList{Items: []*ast.ObjectItem{item}}
558
+	}
559
+
560
+	list, ok := node.(*ast.ObjectList)
561
+	if !ok {
562
+		return &parser.PosError{
563
+			Pos: node.Pos(),
564
+			Err: fmt.Errorf("%s: not an object type for struct (%T)", name, node),
565
+		}
566
+	}
567
+
568
+	// This slice will keep track of all the structs we'll be decoding.
569
+	// There can be more than one struct if there are embedded structs
570
+	// that are squashed.
571
+	structs := make([]reflect.Value, 1, 5)
572
+	structs[0] = result
573
+
574
+	// Compile the list of all the fields that we're going to be decoding
575
+	// from all the structs.
576
+	type field struct {
577
+		field reflect.StructField
578
+		val   reflect.Value
579
+	}
580
+	fields := []field{}
581
+	for len(structs) > 0 {
582
+		structVal := structs[0]
583
+		structs = structs[1:]
584
+
585
+		structType := structVal.Type()
586
+		for i := 0; i < structType.NumField(); i++ {
587
+			fieldType := structType.Field(i)
588
+			tagParts := strings.Split(fieldType.Tag.Get(tagName), ",")
589
+
590
+			// Ignore fields with tag name "-"
591
+			if tagParts[0] == "-" {
592
+				continue
593
+			}
594
+
595
+			if fieldType.Anonymous {
596
+				fieldKind := fieldType.Type.Kind()
597
+				if fieldKind != reflect.Struct {
598
+					return &parser.PosError{
599
+						Pos: node.Pos(),
600
+						Err: fmt.Errorf("%s: unsupported type to struct: %s",
601
+							fieldType.Name, fieldKind),
602
+					}
603
+				}
604
+
605
+				// We have an embedded field. We "squash" the fields down
606
+				// if specified in the tag.
607
+				squash := false
608
+				for _, tag := range tagParts[1:] {
609
+					if tag == "squash" {
610
+						squash = true
611
+						break
612
+					}
613
+				}
614
+
615
+				if squash {
616
+					structs = append(
617
+						structs, result.FieldByName(fieldType.Name))
618
+					continue
619
+				}
620
+			}
621
+
622
+			// Normal struct field, store it away
623
+			fields = append(fields, field{fieldType, structVal.Field(i)})
624
+		}
625
+	}
626
+
627
+	usedKeys := make(map[string]struct{})
628
+	decodedFields := make([]string, 0, len(fields))
629
+	decodedFieldsVal := make([]reflect.Value, 0)
630
+	unusedKeysVal := make([]reflect.Value, 0)
631
+	for _, f := range fields {
632
+		field, fieldValue := f.field, f.val
633
+		if !fieldValue.IsValid() {
634
+			// This should never happen
635
+			panic("field is not valid")
636
+		}
637
+
638
+		// If we can't set the field, then it is unexported or something,
639
+		// and we just continue onwards.
640
+		if !fieldValue.CanSet() {
641
+			continue
642
+		}
643
+
644
+		fieldName := field.Name
645
+
646
+		tagValue := field.Tag.Get(tagName)
647
+		tagParts := strings.SplitN(tagValue, ",", 2)
648
+		if len(tagParts) >= 2 {
649
+			switch tagParts[1] {
650
+			case "decodedFields":
651
+				decodedFieldsVal = append(decodedFieldsVal, fieldValue)
652
+				continue
653
+			case "key":
654
+				if item == nil {
655
+					return &parser.PosError{
656
+						Pos: node.Pos(),
657
+						Err: fmt.Errorf("%s: %s asked for 'key', impossible",
658
+							name, fieldName),
659
+					}
660
+				}
661
+
662
+				fieldValue.SetString(item.Keys[0].Token.Value().(string))
663
+				continue
664
+			case "unusedKeys":
665
+				unusedKeysVal = append(unusedKeysVal, fieldValue)
666
+				continue
667
+			}
668
+		}
669
+
670
+		if tagParts[0] != "" {
671
+			fieldName = tagParts[0]
672
+		}
673
+
674
+		// Determine the element we'll use to decode. If it is a single
675
+		// match (only object with the field), then we decode it exactly.
676
+		// If it is a prefix match, then we decode the matches.
677
+		filter := list.Filter(fieldName)
678
+
679
+		prefixMatches := filter.Children()
680
+		matches := filter.Elem()
681
+		if len(matches.Items) == 0 && len(prefixMatches.Items) == 0 {
682
+			continue
683
+		}
684
+
685
+		// Track the used key
686
+		usedKeys[fieldName] = struct{}{}
687
+
688
+		// Create the field name and decode. We range over the elements
689
+		// because we actually want the value.
690
+		fieldName = fmt.Sprintf("%s.%s", name, fieldName)
691
+		if len(prefixMatches.Items) > 0 {
692
+			if err := d.decode(fieldName, prefixMatches, fieldValue); err != nil {
693
+				return err
694
+			}
695
+		}
696
+		for _, match := range matches.Items {
697
+			var decodeNode ast.Node = match.Val
698
+			if ot, ok := decodeNode.(*ast.ObjectType); ok {
699
+				decodeNode = &ast.ObjectList{Items: ot.List.Items}
700
+			}
701
+
702
+			if err := d.decode(fieldName, decodeNode, fieldValue); err != nil {
703
+				return err
704
+			}
705
+		}
706
+
707
+		decodedFields = append(decodedFields, field.Name)
708
+	}
709
+
710
+	if len(decodedFieldsVal) > 0 {
711
+		// Sort it so that it is deterministic
712
+		sort.Strings(decodedFields)
713
+
714
+		for _, v := range decodedFieldsVal {
715
+			v.Set(reflect.ValueOf(decodedFields))
716
+		}
717
+	}
718
+
719
+	return nil
720
+}
721
+
722
+// findNodeType returns the type of ast.Node
723
+func findNodeType() reflect.Type {
724
+	var nodeContainer struct {
725
+		Node ast.Node
726
+	}
727
+	value := reflect.ValueOf(nodeContainer).FieldByName("Node")
728
+	return value.Type()
729
+}

+ 1203
- 0
vendor/github.com/hashicorp/hcl/decoder_test.go
File diff suppressed because it is too large
View File


+ 3
- 0
vendor/github.com/hashicorp/hcl/go.mod View File

@@ -0,0 +1,3 @@
1
+module github.com/hashicorp/hcl
2
+
3
+require github.com/davecgh/go-spew v1.1.1

+ 2
- 0
vendor/github.com/hashicorp/hcl/go.sum View File

@@ -0,0 +1,2 @@
1
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

+ 11
- 0
vendor/github.com/hashicorp/hcl/hcl.go View File

@@ -0,0 +1,11 @@
1
+// Package hcl decodes HCL into usable Go structures.
2
+//
3
+// hcl input can come in either pure HCL format or JSON format.
4
+// It can be parsed into an AST, and then decoded into a structure,
5
+// or it can be decoded directly from a string into a structure.
6
+//
7
+// If you choose to parse HCL into a raw AST, the benefit is that you
8
+// can write custom visitor implementations to implement custom
9
+// semantic checks. By default, HCL does not perform any semantic
10
+// checks.
11
+package hcl

+ 219
- 0
vendor/github.com/hashicorp/hcl/hcl/ast/ast.go View File

@@ -0,0 +1,219 @@
1
+// Package ast declares the types used to represent syntax trees for HCL
2
+// (HashiCorp Configuration Language)
3
+package ast
4
+
5
+import (
6
+	"fmt"
7
+	"strings"
8
+
9
+	"github.com/hashicorp/hcl/hcl/token"
10
+)
11
+
12
+// Node is an element in the abstract syntax tree.
13
+type Node interface {
14
+	node()
15
+	Pos() token.Pos
16
+}
17
+
18
+func (File) node()         {}
19
+func (ObjectList) node()   {}
20
+func (ObjectKey) node()    {}
21
+func (ObjectItem) node()   {}
22
+func (Comment) node()      {}
23
+func (CommentGroup) node() {}
24
+func (ObjectType) node()   {}
25
+func (LiteralType) node()  {}
26
+func (ListType) node()     {}
27
+
28
+// File represents a single HCL file
29
+type File struct {
30
+	Node     Node            // usually a *ObjectList
31
+	Comments []*CommentGroup // list of all comments in the source
32
+}
33
+
34
+func (f *File) Pos() token.Pos {
35
+	return f.Node.Pos()
36
+}
37
+
38
+// ObjectList represents a list of ObjectItems. An HCL file itself is an
39
+// ObjectList.
40
+type ObjectList struct {
41
+	Items []*ObjectItem
42
+}
43
+
44
+func (o *ObjectList) Add(item *ObjectItem) {
45
+	o.Items = append(o.Items, item)
46
+}
47
+
48
+// Filter filters out the objects with the given key list as a prefix.
49
+//
50
+// The returned list of objects contain ObjectItems where the keys have
51
+// this prefix already stripped off. This might result in objects with
52
+// zero-length key lists if they have no children.
53
+//
54
+// If no matches are found, an empty ObjectList (non-nil) is returned.
55
+func (o *ObjectList) Filter(keys ...string) *ObjectList {
56
+	var result ObjectList
57
+	for _, item := range o.Items {
58
+		// If there aren't enough keys, then ignore this
59
+		if len(item.Keys) < len(keys) {
60
+			continue
61
+		}
62
+
63
+		match := true
64
+		for i, key := range item.Keys[:len(keys)] {
65
+			key := key.Token.Value().(string)
66
+			if key != keys[i] && !strings.EqualFold(key, keys[i]) {
67
+				match = false
68
+				break
69
+			}
70
+		}
71
+		if !match {
72
+			continue
73
+		}
74
+
75
+		// Strip off the prefix from the children
76
+		newItem := *item
77
+		newItem.Keys = newItem.Keys[len(keys):]
78
+		result.Add(&newItem)
79
+	}
80
+
81
+	return &result
82
+}
83
+
84
+// Children returns further nested objects (key length > 0) within this
85
+// ObjectList. This should be used with Filter to get at child items.
86
+func (o *ObjectList) Children() *ObjectList {
87
+	var result ObjectList
88
+	for _, item := range o.Items {
89
+		if len(item.Keys) > 0 {
90
+			result.Add(item)
91
+		}
92
+	}
93
+
94
+	return &result
95
+}
96
+
97
+// Elem returns items in the list that are direct element assignments
98
+// (key length == 0). This should be used with Filter to get at elements.
99
+func (o *ObjectList) Elem() *ObjectList {
100
+	var result ObjectList
101
+	for _, item := range o.Items {
102
+		if len(item.Keys) == 0 {
103
+			result.Add(item)
104
+		}
105
+	}
106
+
107
+	return &result
108
+}
109
+
110
+func (o *ObjectList) Pos() token.Pos {
111
+	// always returns the uninitiliazed position
112
+	return o.Items[0].Pos()
113
+}
114
+
115
+// ObjectItem represents a HCL Object Item. An item is represented with a key
116
+// (or keys). It can be an assignment or an object (both normal and nested)
117
+type ObjectItem struct {
118
+	// keys is only one length long if it's of type assignment. If it's a
119
+	// nested object it can be larger than one. In that case "assign" is
120
+	// invalid as there is no assignments for a nested object.
121
+	Keys []*ObjectKey
122
+
123
+	// assign contains the position of "=", if any
124
+	Assign token.Pos
125
+
126
+	// val is the item itself. It can be an object,list, number, bool or a
127
+	// string. If key length is larger than one, val can be only of type
128
+	// Object.
129
+	Val Node
130
+
131
+	LeadComment *CommentGroup // associated lead comment
132
+	LineComment *CommentGroup // associated line comment
133
+}
134
+
135
+func (o *ObjectItem) Pos() token.Pos {
136
+	// I'm not entirely sure what causes this, but removing this causes
137
+	// a test failure. We should investigate at some point.
138
+	if len(o.Keys) == 0 {
139
+		return token.Pos{}
140
+	}
141
+
142
+	return o.Keys[0].Pos()
143
+}
144
+
145
+// ObjectKeys are either an identifier or of type string.
146
+type ObjectKey struct {
147
+	Token token.Token
148
+}
149
+
150
+func (o *ObjectKey) Pos() token.Pos {
151
+	return o.Token.Pos
152
+}
153
+
154
+// LiteralType represents a literal of basic type. Valid types are:
155
+// token.NUMBER, token.FLOAT, token.BOOL and token.STRING
156
+type LiteralType struct {
157
+	Token token.Token
158
+
159
+	// comment types, only used when in a list
160
+	LeadComment *CommentGroup
161
+	LineComment *CommentGroup
162
+}
163
+
164
+func (l *LiteralType) Pos() token.Pos {
165
+	return l.Token.Pos
166
+}
167
+
168
+// ListStatement represents a HCL List type
169
+type ListType struct {
170
+	Lbrack token.Pos // position of "["
171
+	Rbrack token.Pos // position of "]"
172
+	List   []Node    // the elements in lexical order
173
+}
174
+
175
+func (l *ListType) Pos() token.Pos {
176
+	return l.Lbrack
177
+}
178
+
179
+func (l *ListType) Add(node Node) {
180
+	l.List = append(l.List, node)
181
+}
182
+
183
+// ObjectType represents a HCL Object Type
184
+type ObjectType struct {
185
+	Lbrace token.Pos   // position of "{"
186
+	Rbrace token.Pos   // position of "}"
187
+	List   *ObjectList // the nodes in lexical order
188
+}
189
+
190
+func (o *ObjectType) Pos() token.Pos {
191
+	return o.Lbrace
192
+}
193
+
194
+// Comment node represents a single //, # style or /*- style commment
195
+type Comment struct {
196
+	Start token.Pos // position of / or #
197
+	Text  string
198
+}
199
+
200
+func (c *Comment) Pos() token.Pos {
201
+	return c.Start
202
+}
203
+
204
+// CommentGroup node represents a sequence of comments with no other tokens and
205
+// no empty lines between.
206
+type CommentGroup struct {
207
+	List []*Comment // len(List) > 0
208
+}
209
+
210
+func (c *CommentGroup) Pos() token.Pos {
211
+	return c.List[0].Pos()
212
+}
213
+
214
+//-------------------------------------------------------------------
215
+// GoStringer
216
+//-------------------------------------------------------------------
217
+
218
+func (o *ObjectKey) GoString() string  { return fmt.Sprintf("*%#v", *o) }
219
+func (o *ObjectList) GoString() string { return fmt.Sprintf("*%#v", *o) }

+ 200
- 0
vendor/github.com/hashicorp/hcl/hcl/ast/ast_test.go View File

@@ -0,0 +1,200 @@
1
+package ast
2
+
3
+import (
4
+	"reflect"
5
+	"strings"
6
+	"testing"
7
+
8
+	"github.com/hashicorp/hcl/hcl/token"
9
+)
10
+
11
+func TestObjectListFilter(t *testing.T) {
12
+	var cases = []struct {
13
+		Filter []string
14
+		Input  []*ObjectItem
15
+		Output []*ObjectItem
16
+	}{
17
+		{
18
+			[]string{"foo"},
19
+			[]*ObjectItem{
20
+				&ObjectItem{
21
+					Keys: []*ObjectKey{
22
+						&ObjectKey{
23
+							Token: token.Token{Type: token.STRING, Text: `"foo"`},
24
+						},
25
+					},
26
+				},
27
+			},
28
+			[]*ObjectItem{
29
+				&ObjectItem{
30
+					Keys: []*ObjectKey{},
31
+				},
32
+			},
33
+		},
34
+
35
+		{
36
+			[]string{"foo"},
37
+			[]*ObjectItem{
38
+				&ObjectItem{
39
+					Keys: []*ObjectKey{
40
+						&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"foo"`}},
41
+						&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"bar"`}},
42
+					},
43
+				},
44
+				&ObjectItem{
45
+					Keys: []*ObjectKey{
46
+						&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"baz"`}},
47
+					},
48
+				},
49
+			},
50
+			[]*ObjectItem{
51
+				&ObjectItem{
52
+					Keys: []*ObjectKey{
53
+						&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"bar"`}},
54
+					},
55
+				},
56
+			},
57
+		},
58
+	}
59
+
60
+	for _, tc := range cases {
61
+		input := &ObjectList{Items: tc.Input}
62
+		expected := &ObjectList{Items: tc.Output}
63
+		if actual := input.Filter(tc.Filter...); !reflect.DeepEqual(actual, expected) {
64
+			t.Fatalf("in order: input, expected, actual\n\n%#v\n\n%#v\n\n%#v", input, expected, actual)
65
+		}
66
+	}
67
+}
68
+
69
+func TestWalk(t *testing.T) {
70
+	items := []*ObjectItem{
71
+		&ObjectItem{
72
+			Keys: []*ObjectKey{
73
+				&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"foo"`}},
74
+				&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"bar"`}},
75
+			},
76
+			Val: &LiteralType{Token: token.Token{Type: token.STRING, Text: `"example"`}},
77
+		},
78
+		&ObjectItem{
79
+			Keys: []*ObjectKey{
80
+				&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"baz"`}},
81
+			},
82
+		},
83
+	}
84
+
85
+	node := &ObjectList{Items: items}
86
+
87
+	order := []string{
88
+		"*ast.ObjectList",
89
+		"*ast.ObjectItem",
90
+		"*ast.ObjectKey",
91
+		"*ast.ObjectKey",
92
+		"*ast.LiteralType",
93
+		"*ast.ObjectItem",
94
+		"*ast.ObjectKey",
95
+	}
96
+	count := 0
97
+
98
+	Walk(node, func(n Node) (Node, bool) {
99
+		if n == nil {
100
+			return n, false
101
+		}
102
+
103
+		typeName := reflect.TypeOf(n).String()
104
+		if order[count] != typeName {
105
+			t.Errorf("expected '%s' got: '%s'", order[count], typeName)
106
+		}
107
+		count++
108
+		return n, true
109
+	})
110
+}
111
+
112
+func TestWalkEquality(t *testing.T) {
113
+	items := []*ObjectItem{
114
+		&ObjectItem{
115
+			Keys: []*ObjectKey{
116
+				&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"foo"`}},
117
+			},
118
+		},
119
+		&ObjectItem{
120
+			Keys: []*ObjectKey{
121
+				&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"bar"`}},
122
+			},
123
+		},
124
+	}
125
+
126
+	node := &ObjectList{Items: items}
127
+
128
+	rewritten := Walk(node, func(n Node) (Node, bool) { return n, true })
129
+
130
+	newNode, ok := rewritten.(*ObjectList)
131
+	if !ok {
132
+		t.Fatalf("expected Objectlist, got %T", rewritten)
133
+	}
134
+
135
+	if !reflect.DeepEqual(node, newNode) {
136
+		t.Fatal("rewritten node is not equal to the given node")
137
+	}
138
+
139
+	if len(newNode.Items) != 2 {
140
+		t.Errorf("expected newNode length 2, got: %d", len(newNode.Items))
141
+	}
142
+
143
+	expected := []string{
144
+		`"foo"`,
145
+		`"bar"`,
146
+	}
147
+
148
+	for i, item := range newNode.Items {
149
+		if len(item.Keys) != 1 {
150
+			t.Errorf("expected keys newNode length 1, got: %d", len(item.Keys))
151
+		}
152
+
153
+		if item.Keys[0].Token.Text != expected[i] {
154
+			t.Errorf("expected key %s, got %s", expected[i], item.Keys[0].Token.Text)
155
+		}
156
+
157
+		if item.Val != nil {
158
+			t.Errorf("expected item value should be nil")
159
+		}
160
+	}
161
+}
162
+
163
+func TestWalkRewrite(t *testing.T) {
164
+	items := []*ObjectItem{
165
+		&ObjectItem{
166
+			Keys: []*ObjectKey{
167
+				&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"foo"`}},
168
+				&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"bar"`}},
169
+			},
170
+		},
171
+		&ObjectItem{
172
+			Keys: []*ObjectKey{
173
+				&ObjectKey{Token: token.Token{Type: token.STRING, Text: `"baz"`}},
174
+			},
175
+		},
176
+	}
177
+
178
+	node := &ObjectList{Items: items}
179
+
180
+	suffix := "_example"
181
+	node = Walk(node, func(n Node) (Node, bool) {
182
+		switch i := n.(type) {
183
+		case *ObjectKey:
184
+			i.Token.Text = i.Token.Text + suffix
185
+			n = i
186
+		}
187
+		return n, true
188
+	}).(*ObjectList)
189
+
190
+	Walk(node, func(n Node) (Node, bool) {
191
+		switch i := n.(type) {
192
+		case *ObjectKey:
193
+			if !strings.HasSuffix(i.Token.Text, suffix) {
194
+				t.Errorf("Token '%s' should have suffix: %s", i.Token.Text, suffix)
195
+			}
196
+		}
197
+		return n, true
198
+	})
199
+
200
+}

+ 52
- 0
vendor/github.com/hashicorp/hcl/hcl/ast/walk.go View File

@@ -0,0 +1,52 @@
1
+package ast
2
+
3
+import "fmt"
4
+
5
+// WalkFunc describes a function to be called for each node during a Walk. The
6
+// returned node can be used to rewrite the AST. Walking stops the returned
7
+// bool is false.
8
+type WalkFunc func(Node) (Node, bool)
9
+
10
+// Walk traverses an AST in depth-first order: It starts by calling fn(node);
11
+// node must not be nil. If fn returns true, Walk invokes fn recursively for
12
+// each of the non-nil children of node, followed by a call of fn(nil). The
13
+// returned node of fn can be used to rewrite the passed node to fn.
14
+func Walk(node Node, fn WalkFunc) Node {
15
+	rewritten, ok := fn(node)
16
+	if !ok {
17
+		return rewritten
18
+	}
19
+
20
+	switch n := node.(type) {
21
+	case *File:
22
+		n.Node = Walk(n.Node, fn)
23
+	case *ObjectList:
24
+		for i, item := range n.Items {
25
+			n.Items[i] = Walk(item, fn).(*ObjectItem)
26
+		}
27
+	case *ObjectKey:
28
+		// nothing to do
29
+	case *ObjectItem:
30
+		for i, k := range n.Keys {
31
+			n.Keys[i] = Walk(k, fn).(*ObjectKey)
32
+		}
33
+
34
+		if n.Val != nil {
35
+			n.Val = Walk(n.Val, fn)
36
+		}
37
+	case *LiteralType:
38
+		// nothing to do
39
+	case *ListType:
40
+		for i, l := range n.List {
41
+			n.List[i] = Walk(l, fn)
42
+		}
43
+	case *ObjectType:
44
+		n.List = Walk(n.List, fn).(*ObjectList)
45
+	default:
46
+		// should we panic here?
47
+		fmt.Printf("unknown type: %T\n", n)
48
+	}
49
+
50
+	fn(nil)
51
+	return rewritten
52
+}

+ 162
- 0
vendor/github.com/hashicorp/hcl/hcl/fmtcmd/fmtcmd.go View File

@@ -0,0 +1,162 @@
1
+// Derivative work from:
2
+//	- https://golang.org/src/cmd/gofmt/gofmt.go
3
+//	- https://github.com/fatih/hclfmt
4
+
5
+package fmtcmd
6
+
7
+import (
8
+	"bytes"
9
+	"errors"
10
+	"fmt"
11
+	"io"
12
+	"io/ioutil"
13
+	"os"
14
+	"os/exec"
15
+	"path/filepath"
16
+	"strings"
17
+
18
+	"github.com/hashicorp/hcl/hcl/printer"
19
+)
20
+
21
+var (
22
+	ErrWriteStdin = errors.New("cannot use write option with standard input")
23
+)
24
+
25
+type Options struct {
26
+	List  bool // list files whose formatting differs
27
+	Write bool // write result to (source) file instead of stdout
28
+	Diff  bool // display diffs of formatting changes
29
+}
30
+
31
+func isValidFile(f os.FileInfo, extensions []string) bool {
32
+	if !f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
33
+		for _, ext := range extensions {
34
+			if strings.HasSuffix(f.Name(), "."+ext) {
35
+				return true
36
+			}
37
+		}
38
+	}
39
+
40
+	return false
41
+}
42
+
43
+// If in == nil, the source is the contents of the file with the given filename.
44
+func processFile(filename string, in io.Reader, out io.Writer, stdin bool, opts Options) error {
45
+	if in == nil {
46
+		f, err := os.Open(filename)
47
+		if err != nil {
48
+			return err
49
+		}
50
+		defer f.Close()
51
+		in = f
52
+	}
53
+
54
+	src, err := ioutil.ReadAll(in)
55
+	if err != nil {
56
+		return err
57
+	}
58
+
59
+	res, err := printer.Format(src)
60
+	if err != nil {
61
+		return fmt.Errorf("In %s: %s", filename, err)
62
+	}
63
+
64
+	if !bytes.Equal(src, res) {
65
+		// formatting has changed
66
+		if opts.List {
67
+			fmt.Fprintln(out, filename)
68
+		}
69
+		if opts.Write {
70
+			err = ioutil.WriteFile(filename, res, 0644)
71
+			if err != nil {
72
+				return err
73
+			}
74
+		}
75
+		if opts.Diff {
76
+			data, err := diff(src, res)
77
+			if err != nil {
78
+				return fmt.Errorf("computing diff: %s", err)
79
+			}
80
+			fmt.Fprintf(out, "diff a/%s b/%s\n", filename, filename)
81
+			out.Write(data)
82
+		}
83
+	}
84
+
85
+	if !opts.List && !opts.Write && !opts.Diff {
86
+		_, err = out.Write(res)
87
+	}
88
+
89
+	return err
90
+}
91
+
92
+func walkDir(path string, extensions []string, stdout io.Writer, opts Options) error {
93
+	visitFile := func(path string, f os.FileInfo, err error) error {
94
+		if err == nil && isValidFile(f, extensions) {
95
+			err = processFile(path, nil, stdout, false, opts)
96
+		}
97
+		return err
98
+	}
99
+
100
+	return filepath.Walk(path, visitFile)
101
+}
102
+
103
+func Run(
104
+	paths, extensions []string,
105
+	stdin io.Reader,
106
+	stdout io.Writer,
107
+	opts Options,
108
+) error {
109
+	if len(paths) == 0 {
110
+		if opts.Write {
111
+			return ErrWriteStdin
112
+		}
113
+		if err := processFile("<standard input>", stdin, stdout, true, opts); err != nil {
114
+			return err
115
+		}
116
+		return nil
117
+	}
118
+
119
+	for _, path := range paths {
120
+		switch dir, err := os.Stat(path); {
121
+		case err != nil:
122
+			return err
123
+		case dir.IsDir():
124
+			if err := walkDir(path, extensions, stdout, opts); err != nil {
125
+				return err
126
+			}
127
+		default:
128
+			if err := processFile(path, nil, stdout, false, opts); err != nil {
129
+				return err
130
+			}
131
+		}
132
+	}
133
+
134
+	return nil
135
+}
136
+
137
+func diff(b1, b2 []byte) (data []byte, err error) {
138
+	f1, err := ioutil.TempFile("", "")
139
+	if err != nil {
140
+		return
141
+	}
142
+	defer os.Remove(f1.Name())
143
+	defer f1.Close()
144
+
145
+	f2, err := ioutil.TempFile("", "")
146
+	if err != nil {
147
+		return
148
+	}
149
+	defer os.Remove(f2.Name())
150
+	defer f2.Close()
151
+
152
+	f1.Write(b1)
153
+	f2.Write(b2)
154
+
155
+	data, err = exec.Command("diff", "-u", f1.Name(), f2.Name()).CombinedOutput()
156
+	if len(data) > 0 {
157
+		// diff exits with a non-zero status when the files don't match.
158
+		// Ignore that failure as long as we get output.
159
+		err = nil
160
+	}
161
+	return
162
+}

+ 440
- 0
vendor/github.com/hashicorp/hcl/hcl/fmtcmd/fmtcmd_test.go View File

@@ -0,0 +1,440 @@
1
+// +build !windows
2
+// TODO(jen20): These need fixing on Windows but fmt is not used right now
3
+// and red CI is making it harder to process other bugs, so ignore until
4
+// we get around to fixing them.
5
+
6
+package fmtcmd
7
+
8
+import (
9
+	"bytes"
10
+	"fmt"
11
+	"io/ioutil"
12
+	"os"
13
+	"path/filepath"
14
+	"reflect"
15
+	"regexp"
16
+	"sort"
17
+	"syscall"
18
+	"testing"
19
+
20
+	"github.com/hashicorp/hcl/testhelper"
21
+)
22
+
23
+var fixtureExtensions = []string{"hcl"}
24
+
25
+func init() {
26
+	sort.Sort(ByFilename(fixtures))
27
+}
28
+
29
+func TestIsValidFile(t *testing.T) {
30
+	const fixtureDir = "./test-fixtures"
31
+
32
+	cases := []struct {
33
+		Path     string
34
+		Expected bool
35
+	}{
36
+		{"good.hcl", true},
37
+		{".hidden.ignore", false},
38
+		{"file.ignore", false},
39
+		{"dir.ignore", false},
40
+	}
41
+
42
+	for _, tc := range cases {
43
+		file, err := os.Stat(filepath.Join(fixtureDir, tc.Path))
44
+		if err != nil {
45
+			t.Errorf("unexpected error: %s", err)
46
+		}
47
+
48
+		if res := isValidFile(file, fixtureExtensions); res != tc.Expected {
49
+			t.Errorf("want: %t, got: %t", tc.Expected, res)
50
+		}
51
+	}
52
+}
53
+
54
+func TestRunMultiplePaths(t *testing.T) {
55
+	path1, err := renderFixtures("")
56
+	if err != nil {
57
+		t.Errorf("unexpected error: %s", err)
58
+	}
59
+	defer os.RemoveAll(path1)
60
+	path2, err := renderFixtures("")
61
+	if err != nil {
62
+		t.Errorf("unexpected error: %s", err)
63
+	}
64
+	defer os.RemoveAll(path2)
65
+
66
+	var expectedOut bytes.Buffer
67
+	for _, path := range []string{path1, path2} {
68
+		for _, fixture := range fixtures {
69
+			if !bytes.Equal(fixture.golden, fixture.input) {
70
+				expectedOut.WriteString(filepath.Join(path, fixture.filename) + "\n")
71
+			}
72
+		}
73
+	}
74
+
75
+	_, stdout := mockIO()
76
+	err = Run(
77
+		[]string{path1, path2},
78
+		fixtureExtensions,
79
+		nil, stdout,
80
+		Options{
81
+			List: true,
82
+		},
83
+	)