Skip to content

Commit 0e3082f

Browse files
deepcubeldelossa
authored andcommitted
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}}
1 parent 6fbc522 commit 0e3082f

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/mattn/go-colorable v0.0.9 // indirect
2929
github.com/mattn/go-isatty v0.0.3 // indirect
3030
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
31+
github.com/mitchellh/go-wordwrap v1.0.1
3132
github.com/olekukonko/tablewriter v0.0.3
3233
github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15
3334
github.com/pkg/errors v0.8.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ github.com/mattn/go-runewidth v0.0.6 h1:V2iyH+aX9C5fsYCpK60U8BYIvmhqxuOL3JZcqc1N
5555
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
5656
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
5757
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
58+
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
59+
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
5860
github.com/olekukonko/tablewriter v0.0.3 h1:i0LBnzgiChAWHJYTQAZJDOgf8MNxAVYZJ2m63SIDimI=
5961
github.com/olekukonko/tablewriter v0.0.3/go.mod h1:YZeBtGzYYEsCHp2LST/u/0NDwGkRoBtmn1cIWCJiS6M=
6062
github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15 h1:mrI+6Ae64Wjt+uahGe5we/sPS1sXjvfT3YjtawAVgps=

jiracli/templates.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
shellquote "github.com/kballard/go-shellquote"
2222
"github.com/mgutz/ansi"
2323
"github.com/olekukonko/tablewriter"
24+
wordwrap "github.com/mitchellh/go-wordwrap"
2425
"golang.org/x/crypto/ssh/terminal"
2526
)
2627

@@ -191,6 +192,9 @@ func TemplateProcessor() *template.Template {
191192
"dateFormat": func(format string, content string) (string, error) {
192193
return dateFormat(format, content)
193194
},
195+
"wrap": func(width uint, content string) string {
196+
return wordwrap.WrapString(content, width)
197+
},
194198
}
195199
return template.New("gojira").Funcs(sprig.GenericFuncMap()).Funcs(funcs)
196200
}

0 commit comments

Comments
 (0)