Bump github.com/containers/common from 0.33.1 to 0.34.0

Bumps [github.com/containers/common](https://github.com/containers/common) from 0.33.1 to 0.34.0.
- [Release notes](https://github.com/containers/common/releases)
- [Commits](https://github.com/containers/common/compare/v0.33.1...v0.34.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
dependabot-preview[bot]
2021-02-02 09:16:57 +00:00
committed by Daniel J Walsh
parent 3375a905cc
commit 4ab7faa800
5 changed files with 35 additions and 29 deletions

View File

@@ -38,7 +38,17 @@ Helpers:
... process JSON and output
}
and
Template Functions:
The following template functions are added to the template when parsed:
- join strings.Join, {{join .Field separator}}
- lower strings.ToLower {{ .Field | lower }}
- split strings.Split {{ .Field | split }}
- title strings.Title {{ .Field | title }}
- upper strings.ToUpper {{ .Field | upper }}
report.Funcs() may be used to add additional template functions.
Adding an existing function will replace that function for the life of that template.
Note: Your code should not ignore errors

View File

@@ -31,6 +31,14 @@ var escapedReplacer = strings.NewReplacer(
`\n`, "\n",
)
var defaultFuncs = FuncMap{
"join": strings.Join,
"lower": strings.ToLower,
"split": strings.Split,
"title": strings.Title,
"upper": strings.ToUpper,
}
// NormalizeFormat reads given go template format provided by CLI and munges it into what we need
func NormalizeFormat(format string) string {
var f string
@@ -88,7 +96,7 @@ func Headers(object interface{}, overrides map[string]string) []map[string]strin
// NewTemplate creates a new template object
func NewTemplate(name string) *Template {
return &Template{template.New(name), false}
return &Template{Template: template.New(name).Funcs(template.FuncMap(defaultFuncs))}
}
// Parse parses text as a template body for t
@@ -100,13 +108,21 @@ func (t *Template) Parse(text string) (*Template, error) {
text = NormalizeFormat(text)
}
tt, err := t.Template.Parse(text)
tt, err := t.Template.Funcs(template.FuncMap(defaultFuncs)).Parse(text)
return &Template{tt, t.isTable}, err
}
// Funcs adds the elements of the argument map to the template's function map
// Funcs adds the elements of the argument map to the template's function map.
// A default template function will be replace if there is a key collision.
func (t *Template) Funcs(funcMap FuncMap) *Template {
return &Template{t.Template.Funcs(template.FuncMap(funcMap)), t.isTable}
m := make(FuncMap)
for k, v := range defaultFuncs {
m[k] = v
}
for k, v := range funcMap {
m[k] = v
}
return &Template{Template: t.Template.Funcs(template.FuncMap(m)), isTable: t.isTable}
}
// IsTable returns true if format string defines a "table"