Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cli/command/container/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func buildContainerListOptions(options *psOptions) (*container.ListOptions, erro

// always validate template when `--format` is used, for consistency
if len(options.format) > 0 {
tmpl, err := templates.NewParse("", options.format)
tmpl, err := templates.Parse(options.format)
if err != nil {
return nil, errors.Wrap(err, "failed to parse template")
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func needsServerInfo(template string, info dockerInfo) bool {
}

// A template is provided and has at least one field set.
tmpl, err := templates.NewParse("", template)
tmpl, err := templates.Parse(template)
if err != nil {
// ignore parsing errors here, and let regular code handle them
return true
Expand Down
3 changes: 1 addition & 2 deletions cli/command/system/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ func newVersionTemplate(templateFormat string) (*template.Template, error) {
case formatter.JSONFormatKey:
templateFormat = formatter.JSONFormat
}
tmpl := templates.New("version").Funcs(template.FuncMap{"getDetailsOrder": getDetailsOrder})
tmpl, err := tmpl.Parse(templateFormat)
tmpl, err := templates.New("version").Funcs(template.FuncMap{"getDetailsOrder": getDetailsOrder}).Parse(templateFormat)
if err != nil {
return nil, errors.Wrap(err, "template parsing error")
}
Expand Down
6 changes: 4 additions & 2 deletions templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var HeaderFunctions = template.FuncMap{
// Parse creates a new anonymous template with the basic functions
// and parses the given format.
func Parse(format string) (*template.Template, error) {
return NewParse("", format)
return template.New("").Funcs(basicFunctions).Parse(format)
}

// New creates a new empty template with the provided tag and built-in
Expand All @@ -82,8 +82,10 @@ func New(tag string) *template.Template {

// NewParse creates a new tagged template with the basic functions
// and parses the given format.
//
// Deprecated: this function is unused and will be removed in the next release. Use [New] if you need to set a tag, or [Parse] instead.
func NewParse(tag, format string) (*template.Template, error) {
return New(tag).Parse(format)
return template.New(tag).Funcs(basicFunctions).Parse(format)
}

// padWithSpace adds whitespace to the input if the input is non-empty
Expand Down
2 changes: 1 addition & 1 deletion templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestParseStringFunctions(t *testing.T) {
}

func TestNewParse(t *testing.T) {
tm, err := NewParse("foo", "this is a {{ . }}")
tm, err := New("foo").Parse("this is a {{ . }}")
assert.NilError(t, err)

var b bytes.Buffer
Expand Down
Loading