Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add template functions #215

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions jiracli/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,39 @@ func TemplateProcessor() *template.Template {
"sub": func(a, b int) int {
return a - b
},
"sum": func(num int, nums ...int) int {
for _, n := range nums {
num += n
}
return num
},
"prod": func(num int, nums ...int) int {
for _, n := range nums {
num *= n
}
return num
},
"div": func(a, b int) int {
// This is intentionally integer division.
// 1/2 a character width is unlikely to be useful.
return a / b
},
"min": func(num int, nums ...int) int {
for _, n := range nums {
if n < num {
num = n
}
}
return num
},
"max": func(num int, nums ...int) int {
for _, n := range nums {
if n > num {
num = n
}
}
return num
},
"append": func(more string, content interface{}) (string, error) {
switch value := content.(type) {
case string:
Expand Down