feat(template): list func to funcmap
This commit is contained in:
parent
99abdf4a31
commit
25b4363c5f
1 changed files with 11 additions and 0 deletions
11
cmd/get.go
11
cmd/get.go
|
|
@ -166,6 +166,17 @@ func applyTemplate(tplBytes []byte, substitutions []string) ([]byte, error) {
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
},
|
},
|
||||||
|
"list": func(v any) []string {
|
||||||
|
s := fmt.Sprint(v)
|
||||||
|
if s == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
parts := strings.Split(s, ",")
|
||||||
|
for i := range parts {
|
||||||
|
parts[i] = strings.TrimSpace(parts[i])
|
||||||
|
}
|
||||||
|
return parts
|
||||||
|
},
|
||||||
}
|
}
|
||||||
tpl, err := template.New("cmd").
|
tpl, err := template.New("cmd").
|
||||||
Delims("{{", "}}").
|
Delims("{{", "}}").
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue