/
util.go
36 lines (27 loc) · 719 Bytes
/
util.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
package prompts
import (
"bytes"
"text/template"
"github.com/manifoldco/promptui"
"github.com/manifoldco/torus-cli/errs"
)
const validationErrorTmpl = ` {{ . | faint }}`
func convertErr(err error) error {
if err == promptui.ErrAbort || err == promptui.ErrInterrupt || err == promptui.ErrEOF {
return errs.ErrAbort
}
return err
}
func direct(tpl string, data interface{}, value string) string {
t, err := template.New("").Funcs(promptui.FuncMap).Parse(tpl)
if err != nil {
panic("could not parse template: " + err.Error())
}
var buf bytes.Buffer
err = t.Execute(&buf, data)
if err != nil {
panic("could not render template: " + err.Error())
}
buf.WriteString(value)
return buf.String()
}