templates: add wrap helper function

Add "wrap" command to TemplateProcessor.  Use
github.com/mitchellh/go-wordwrap to wrap lines on word breaks at
a given length.  This can make long fields much more readable in
a terminal.  E.g.

	{{ .fields.description | wrap 76 | indent 2}}
This commit is contained in:
Evan Gates
2020-09-30 07:57:46 -07:00
committed by Louis DeLosSantos
parent 6fbc522ee7
commit 0e3082fab6
3 changed files with 7 additions and 0 deletions
+4
View File
@@ -21,6 +21,7 @@ import (
shellquote "github.com/kballard/go-shellquote"
"github.com/mgutz/ansi"
"github.com/olekukonko/tablewriter"
wordwrap "github.com/mitchellh/go-wordwrap"
"golang.org/x/crypto/ssh/terminal"
)
@@ -191,6 +192,9 @@ func TemplateProcessor() *template.Template {
"dateFormat": func(format string, content string) (string, error) {
return dateFormat(format, content)
},
"wrap": func(width uint, content string) string {
return wordwrap.WrapString(content, width)
},
}
return template.New("gojira").Funcs(sprig.GenericFuncMap()).Funcs(funcs)
}