Merge pull request #4910 from ColinHebert/trim
Add the trimspace() interpolation function
This commit is contained in:
commit
f9e369c204
|
@ -41,6 +41,7 @@ func Funcs() map[string]ast.Function {
|
|||
"split": interpolationFuncSplit(),
|
||||
"sha1": interpolationFuncSha1(),
|
||||
"sha256": interpolationFuncSha256(),
|
||||
"trimspace": interpolationFuncTrimSpace(),
|
||||
"base64encode": interpolationFuncBase64Encode(),
|
||||
"base64decode": interpolationFuncBase64Decode(),
|
||||
"upper": interpolationFuncUpper(),
|
||||
|
@ -617,3 +618,14 @@ func interpolationFuncSha256() ast.Function {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
func interpolationFuncTrimSpace() ast.Function {
|
||||
return ast.Function{
|
||||
ArgTypes: []ast.Type{ast.TypeString},
|
||||
ReturnType: ast.TypeString,
|
||||
Callback: func(args []interface{}) (interface{}, error) {
|
||||
trimSpace := args[0].(string)
|
||||
return strings.TrimSpace(trimSpace), nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -858,6 +858,18 @@ func TestInterpolateFuncSha256(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestInterpolateFuncTrimSpace(t *testing.T) {
|
||||
testFunction(t, testFunctionConfig{
|
||||
Cases: []testFunctionCase{
|
||||
{
|
||||
`${trimspace(" test ")}`,
|
||||
"test",
|
||||
false,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type testFunctionConfig struct {
|
||||
Cases []testFunctionCase
|
||||
Vars map[string]ast.Variable
|
||||
|
|
|
@ -176,6 +176,8 @@ The supported built-in functions are:
|
|||
`a_resource_param = ["${split(",", var.CSV_STRING)}"]`.
|
||||
Example: `split(",", module.amod.server_ids)`
|
||||
|
||||
* `trimspace(string)` - Returns a copy of the string with all leading and trailing white spaces removed.
|
||||
|
||||
* `upper(string)` - Returns a copy of the string with all Unicode letters mapped to their upper case.
|
||||
|
||||
## Templates
|
||||
|
|
Loading…
Reference in New Issue