updated common to 0.35.0

Signed-off-by: Parker Van Roy <pvanroy@redhat.com>
This commit is contained in:
Parker Van Roy
2021-02-22 16:09:39 -05:00
parent 836bfebb46
commit ccbe4ff73f
7 changed files with 26 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"reflect"
"regexp"
"strings"
"text/template"
@@ -155,3 +156,18 @@ func (t *Template) Funcs(funcMap FuncMap) *Template {
func (t *Template) IsTable() bool {
return t.isTable
}
var rangeRegex = regexp.MustCompile(`{{\s*range\s*\.\s*}}.*{{\s*end\s*}}`)
// EnforceRange ensures that the format string contains a range
func EnforceRange(format string) string {
if !rangeRegex.MatchString(format) {
return "{{range .}}" + format + "{{end}}"
}
return format
}
// HasTable returns whether the format is a table
func HasTable(format string) bool {
return strings.HasPrefix(format, "table ")
}