-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameter.go
89 lines (75 loc) · 1.61 KB
/
parameter.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package tekton
import (
"fmt"
"strings"
)
type identParam struct {
value interface{}
parent interface{}
parentKind string
parentName string
}
func IdentParameter(v StringMap, parent interface{}) *identParam {
p := &identParam{
value: v,
parent: parent,
}
pm := parent.(map[string]interface{})
kind, ok := pm["kind"].(string)
if ok {
p.parentKind = strings.ToLower(kind)
}
var meta map[string]interface{}
if m, ok := pm["metadata"]; ok {
meta, _ = m.(map[string]interface{})
}
if meta != nil {
p.parentName, _ = meta["name"].(string)
}
return p
}
var _ Meta = &identParam{}
func (p *identParam) Completions() []completion {
cs := []completion{}
if p.Type() == "array" {
cs = append(cs,
completion{
text: fmt.Sprintf("$(params.%s[*])", p.Name()),
},
)
} else {
cs = append(cs,
completion{
text: fmt.Sprintf("$(params.%s)", p.Name()),
},
)
}
return cs
}
func (p *identParam) Name() string {
n, _ := StringMap(p.value.(map[string]interface{}))["name"].(string)
return n
}
func (p *identParam) Default() string {
d, _ := StringMap(p.value.(map[string]interface{}))["default"].(string)
return d
}
func (p *identParam) Type() string {
if t, ok := StringMap(p.value.(map[string]interface{}))["type"].(string); ok {
return t
}
return "string"
}
func (p *identParam) Description() string {
d, _ := StringMap(p.value.(map[string]interface{}))["description"].(string)
return d
}
func (p *identParam) Documentation() string {
return fmt.Sprintf(
"```yaml\nname: %s\ndefault: %s\ntype: %s\n%s\n```",
p.Name(),
p.Default(),
p.Type(),
p.Description(),
)
}