Skip to content

Commit 16b5302

Browse files
committed
release v1.7.0-beta-5
2 parents 621449f + e4409a8 commit 16b5302

11 files changed

Lines changed: 87 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ list:
16211621
contains: true
16221622
```
16231623

1624-
The function `contains` also works on strings to look for sub strings.
1624+
The function `contains` also works on strings to look for sub strings or maps to look for a key. In those cases the element must be a string.
16251625

16261626
e.g.:
16271627

dynaml/contains.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package dynaml
22

33
import (
4-
"github.com/mandelsoft/spiff/yaml"
54
"strconv"
65
"strings"
6+
7+
"github.com/mandelsoft/spiff/yaml"
78
)
89

910
func func_contains(arguments []interface{}, binding Binding) (interface{}, EvaluationInfo, bool) {
@@ -14,6 +15,18 @@ func func_contains(arguments []interface{}, binding Binding) (interface{}, Evalu
1415
}
1516

1617
switch val := arguments[0].(type) {
18+
case map[string]yaml.Node:
19+
elem := arguments[1]
20+
if elem == nil {
21+
return false, info, true
22+
}
23+
key, ok := elem.(string)
24+
if !ok {
25+
return false, info, true
26+
}
27+
_, ok = val[key]
28+
return ok, info, true
29+
1730
case []yaml.Node:
1831
if arguments[1] == nil {
1932
return false, info, true

dynaml/exec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func cachedExecute(cache ExecCache, content *string, args []string) ([]byte, err
135135
if content != nil {
136136
h.Write([]byte(*content))
137137
}
138+
args[0] = FilePath(args[0])
138139
for _, arg := range args {
139140
h.Write([]byte(arg))
140141
}

dynaml/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ func (r *registry) IsTemplateControlOption(name string) bool {
5858

5959
func DefaultRegistry() Registry {
6060
var r *registry
61-
return r // standard beaviour support on nil pointer inter
61+
return r // standard behaviour support on nil pointer inter
6262
}

dynaml/write.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ func getWriteOptions(arg interface{}, wopt WriteOpts, permonly bool) (WriteOpts,
9797
return wopt, err
9898
}
9999

100+
func FilePath(file string) string {
101+
if strings.HasPrefix(file, "~/") {
102+
home := os.Getenv("HOME")
103+
if home != "" {
104+
file = home + file[1:]
105+
}
106+
}
107+
return file
108+
}
109+
100110
func getData(file string, wopt WriteOpts, key interface{}, value interface{}, yaml bool) (string, string, []byte, bool) {
101111
var data []byte
102112
var err error
@@ -110,5 +120,5 @@ func getData(file string, wopt WriteOpts, key interface{}, value interface{}, ya
110120
} else {
111121
data = []byte(str)
112122
}
113-
return removeTags(file), str, data, err == nil
123+
return FilePath(removeTags(file)), str, data, err == nil
114124
}

flow/flow_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3625,6 +3625,28 @@ uniq:
36253625
})
36263626

36273627
Describe("when calling contains", func() {
3628+
It("handes maps", func() {
3629+
source := parseYAML(`
3630+
---
3631+
map:
3632+
a: alice
3633+
b: bob
3634+
contains:
3635+
a: (( contains(map, "a") ))
3636+
c: (( contains(map, "c") ))
3637+
`)
3638+
resolved := parseYAML(`
3639+
---
3640+
contains:
3641+
a: true
3642+
c: false
3643+
map:
3644+
a: alice
3645+
b: bob
3646+
`)
3647+
Expect(source).To(FlowAs(resolved))
3648+
})
3649+
36283650
It("finds ints", func() {
36293651
source := parseYAML(`
36303652
---

flow/state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ func (s *State) Cleanup() {
297297
func (s *State) GetFileContent(file string, cached bool) ([]byte, error) {
298298
var err error
299299

300+
file = dynaml.FilePath(file)
300301
data := s.fileCache[file]
301302
if !cached || data == nil {
302303
debug.Debug("reading file %s\n", file)

flow/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package flow
22

3-
var VERSION = "v1.7.0-beta-4"
3+
var VERSION = "v1.7.0-beta-5"

spiffing/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ type Options = flow.Options
3030
// the standard function set
3131
type Functions = dynaml.Functions
3232

33+
// Function is the signature of a dynaml function
34+
type Function = dynaml.Function
35+
3336
// Controls provides access to a set of spiff controls used to extend
3437
// the standard control set
3538
type Controls = dynaml.Controls

spiffing/spiff.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func New() Spiff {
9292
key: features.EncryptionKey(),
9393
mode: MODE_DEFAULT,
9494
features: features.Features(),
95+
registry: dynaml.DefaultRegistry(),
9596
}
9697
}
9798

@@ -102,6 +103,7 @@ func Plain() Spiff {
102103
key: "",
103104
mode: MODE_DEFAULT,
104105
features: features.FeatureFlags{},
106+
registry: dynaml.DefaultRegistry(),
105107
}
106108
}
107109

0 commit comments

Comments
 (0)