Order functions alphabetically
This commit is contained in:
parent
735803ef09
commit
ef2b0a0b71
|
@ -20,22 +20,38 @@ var Funcs map[string]ast.Function
|
|||
|
||||
func init() {
|
||||
Funcs = map[string]ast.Function{
|
||||
"concat": interpolationFuncConcat(),
|
||||
"element": interpolationFuncElement(),
|
||||
"file": interpolationFuncFile(),
|
||||
"format": interpolationFuncFormat(),
|
||||
"formatlist": interpolationFuncFormatList(),
|
||||
"index": interpolationFuncIndex(),
|
||||
"join": interpolationFuncJoin(),
|
||||
"length": interpolationFuncLength(),
|
||||
"replace": interpolationFuncReplace(),
|
||||
"split": interpolationFuncSplit(),
|
||||
"compact": interpolationFuncCompact(),
|
||||
"concat": interpolationFuncConcat(),
|
||||
"element": interpolationFuncElement(),
|
||||
"file": interpolationFuncFile(),
|
||||
"format": interpolationFuncFormat(),
|
||||
"formatlist": interpolationFuncFormatList(),
|
||||
"index": interpolationFuncIndex(),
|
||||
"join": interpolationFuncJoin(),
|
||||
"length": interpolationFuncLength(),
|
||||
"replace": interpolationFuncReplace(),
|
||||
"split": interpolationFuncSplit(),
|
||||
"base64encode": interpolationFuncBase64Encode(),
|
||||
"base64decode": interpolationFuncBase64Decode(),
|
||||
}
|
||||
}
|
||||
|
||||
// interpolationFuncCompact strips a list of multi-variable values
|
||||
// (e.g. as returned by "split") of any empty strings.
|
||||
func interpolationFuncCompact() ast.Function {
|
||||
return ast.Function{
|
||||
ArgTypes: []ast.Type{ast.TypeString},
|
||||
ReturnType: ast.TypeString,
|
||||
Variadic: false,
|
||||
Callback: func(args []interface{}) (interface{}, error) {
|
||||
if !IsStringList(args[0].(string)) {
|
||||
return args[0].(string), nil
|
||||
}
|
||||
return CompactStringList(StringList(args[0].(string))).String(), nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// interpolationFuncConcat implements the "concat" function that
|
||||
// concatenates multiple strings. This isn't actually necessary anymore
|
||||
// since our language supports string concat natively, but for backwards
|
||||
|
@ -280,22 +296,6 @@ func interpolationFuncSplit() ast.Function {
|
|||
}
|
||||
}
|
||||
|
||||
// interpolationFuncCompact strips a list of values (e.g. as returned by
|
||||
// "split") of any empty strings
|
||||
func interpolationFuncCompact() ast.Function {
|
||||
return ast.Function{
|
||||
ArgTypes: []ast.Type{ast.TypeString},
|
||||
ReturnType: ast.TypeString,
|
||||
Variadic: false,
|
||||
Callback: func(args []interface{}) (interface{}, error) {
|
||||
if !IsStringList(args[0].(string)) {
|
||||
return args[0].(string), nil
|
||||
}
|
||||
return CompactStringList(StringList(args[0].(string))).String(), nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// interpolationFuncLookup implements the "lookup" function that allows
|
||||
// dynamic lookups of map types within a Terraform configuration.
|
||||
func interpolationFuncLookup(vs map[string]ast.Variable) ast.Function {
|
||||
|
|
|
@ -24,6 +24,20 @@ type StringList string
|
|||
// ["", ""] => SLDSLDSLD
|
||||
const stringListDelim = `B780FFEC-B661-4EB8-9236-A01737AD98B6`
|
||||
|
||||
// Takes a Stringlist and returns one without empty strings in it
|
||||
func (sl StringList) CompactStringList() StringList {
|
||||
parts := sl.Slice()
|
||||
|
||||
var newlist []string
|
||||
// drop the empty strings
|
||||
for i := range parts {
|
||||
if parts[i] != "" {
|
||||
newlist = append(newlist, parts[i])
|
||||
}
|
||||
}
|
||||
return NewStringList(newlist)
|
||||
}
|
||||
|
||||
// Build a StringList from a slice
|
||||
func NewStringList(parts []string) StringList {
|
||||
// We have to special case the empty list representation
|
||||
|
@ -74,16 +88,3 @@ func (sl StringList) String() string {
|
|||
func IsStringList(s string) bool {
|
||||
return strings.Contains(s, stringListDelim)
|
||||
}
|
||||
|
||||
func CompactStringList(sl StringList) StringList {
|
||||
parts := sl.Slice()
|
||||
|
||||
var newlist []string
|
||||
// drop the empty strings
|
||||
for i := range parts {
|
||||
if parts[i] != "" {
|
||||
newlist = append(newlist, parts[i])
|
||||
}
|
||||
}
|
||||
return NewStringList(newlist)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue