Skip to content

Commit fdc4397

Browse files
authored
Merge pull request docker#6214 from thaJeztah/template_deprecate_newparse
templates: deprecate NewParse()
2 parents a1035b0 + 7ab3e7e commit fdc4397

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

cli/command/container/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func buildContainerListOptions(options *psOptions) (*container.ListOptions, erro
8282

8383
// always validate template when `--format` is used, for consistency
8484
if len(options.format) > 0 {
85-
tmpl, err := templates.NewParse("", options.format)
85+
tmpl, err := templates.Parse(options.format)
8686
if err != nil {
8787
return nil, errors.Wrap(err, "failed to parse template")
8888
}

cli/command/system/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func needsServerInfo(template string, info dockerInfo) bool {
162162
}
163163

164164
// A template is provided and has at least one field set.
165-
tmpl, err := templates.NewParse("", template)
165+
tmpl, err := templates.Parse(template)
166166
if err != nil {
167167
// ignore parsing errors here, and let regular code handle them
168168
return true

cli/command/system/version.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ func newVersionTemplate(templateFormat string) (*template.Template, error) {
209209
case formatter.JSONFormatKey:
210210
templateFormat = formatter.JSONFormat
211211
}
212-
tmpl := templates.New("version").Funcs(template.FuncMap{"getDetailsOrder": getDetailsOrder})
213-
tmpl, err := tmpl.Parse(templateFormat)
212+
tmpl, err := templates.New("version").Funcs(template.FuncMap{"getDetailsOrder": getDetailsOrder}).Parse(templateFormat)
214213
if err != nil {
215214
return nil, errors.Wrap(err, "template parsing error")
216215
}

templates/templates.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var HeaderFunctions = template.FuncMap{
7171
// Parse creates a new anonymous template with the basic functions
7272
// and parses the given format.
7373
func Parse(format string) (*template.Template, error) {
74-
return NewParse("", format)
74+
return template.New("").Funcs(basicFunctions).Parse(format)
7575
}
7676

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

8383
// NewParse creates a new tagged template with the basic functions
8484
// and parses the given format.
85+
//
86+
// 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.
8587
func NewParse(tag, format string) (*template.Template, error) {
86-
return New(tag).Parse(format)
88+
return template.New(tag).Funcs(basicFunctions).Parse(format)
8789
}
8890

8991
// padWithSpace adds whitespace to the input if the input is non-empty

templates/templates_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestParseStringFunctions(t *testing.T) {
3030
}
3131

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

3636
var b bytes.Buffer

0 commit comments

Comments
 (0)