-
Notifications
You must be signed in to change notification settings - Fork 873
/
functionentry.go
52 lines (46 loc) · 1.07 KB
/
functionentry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package jmespath
import (
"fmt"
"strings"
gojmespath "github.com/kyverno/go-jmespath"
)
var (
jpObject = gojmespath.JpObject
jpString = gojmespath.JpString
jpNumber = gojmespath.JpNumber
jpArray = gojmespath.JpArray
jpArrayString = gojmespath.JpArrayString
jpAny = gojmespath.JpAny
jpBool = gojmespath.JpType("bool")
)
type (
jpType = gojmespath.JpType
argSpec = gojmespath.ArgSpec
)
type FunctionEntry struct {
gojmespath.FunctionEntry
Note string
ReturnType []jpType
}
func (f FunctionEntry) String() string {
if f.Name == "" {
return ""
}
var args []string
for _, a := range f.Arguments {
var aTypes []string
for _, t := range a.Types {
aTypes = append(aTypes, string(t))
}
args = append(args, strings.Join(aTypes, "|"))
}
var returnArgs []string
for _, ra := range f.ReturnType {
returnArgs = append(returnArgs, string(ra))
}
output := fmt.Sprintf("%s(%s) %s", f.Name, strings.Join(args, ", "), strings.Join(returnArgs, ","))
if f.Note != "" {
output += fmt.Sprintf(" (%s)", f.Note)
}
return output
}