|
|
|
|
@ -71,6 +71,7 @@ func Funcs() map[string]ast.Function {
|
|
|
|
|
"lower": interpolationFuncLower(),
|
|
|
|
|
"md5": interpolationFuncMd5(),
|
|
|
|
|
"uuid": interpolationFuncUUID(),
|
|
|
|
|
"uniq": interpolationFuncUniq(),
|
|
|
|
|
"replace": interpolationFuncReplace(),
|
|
|
|
|
"sha1": interpolationFuncSha1(),
|
|
|
|
|
"sha256": interpolationFuncSha256(),
|
|
|
|
|
@ -382,6 +383,42 @@ func interpolationFuncIndex() ast.Function {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// interpolationFuncUniq implements the "uniq" function that
|
|
|
|
|
// removes duplicate elements from a list.
|
|
|
|
|
func interpolationFuncUniq() ast.Function {
|
|
|
|
|
return ast.Function{
|
|
|
|
|
ArgTypes: []ast.Type{ast.TypeList},
|
|
|
|
|
ReturnType: ast.TypeList,
|
|
|
|
|
Variadic: true,
|
|
|
|
|
VariadicType: ast.TypeList,
|
|
|
|
|
Callback: func(args []interface{}) (interface{}, error) {
|
|
|
|
|
var list []string
|
|
|
|
|
|
|
|
|
|
if len(args) != 1 {
|
|
|
|
|
return nil, fmt.Errorf("uniq() excepts only one argument.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if argument, ok := args[0].([]ast.Variable); ok {
|
|
|
|
|
for _, element := range argument {
|
|
|
|
|
list = appendIfMissing(list, element.Value.(string))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stringSliceToVariableValue(list), nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// helper function to add an element to a list, if it does not already exsit
|
|
|
|
|
func appendIfMissing(slice []string, element string) []string {
|
|
|
|
|
for _, ele := range slice {
|
|
|
|
|
if ele == element {
|
|
|
|
|
return slice
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return append(slice, element)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// interpolationFuncJoin implements the "join" function that allows
|
|
|
|
|
// multi-variable values to be joined by some character.
|
|
|
|
|
func interpolationFuncJoin() ast.Function {
|
|
|
|
|
|