You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
templates: make "join" work with non-string slices and map values
Add a custom join function that allows for non-string slices to be
joined, following the same rules as "fmt.Sprint", it will use the
fmt.Stringer interface if implemented, or "error" if the type has
an "Error()".
For maps, it joins the map-values, for example:
docker image inspect --format '{{join .Config.Labels ", "}}' ubuntu
24.04, ubuntu
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copy file name to clipboardExpand all lines: templates/templates.go
+41-1Lines changed: 41 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,9 @@ package templates
6
6
import (
7
7
"bytes"
8
8
"encoding/json"
9
+
"fmt"
10
+
"reflect"
11
+
"sort"
9
12
"strings"
10
13
"text/template"
11
14
)
@@ -26,7 +29,7 @@ var basicFunctions = template.FuncMap{
26
29
returnstrings.TrimSpace(buf.String())
27
30
},
28
31
"split": strings.Split,
29
-
"join": strings.Join,
32
+
"join": joinElements,
30
33
"title": strings.Title, //nolint:nolintlint,staticcheck // strings.Title is deprecated, but we only use it for ASCII, so replacing with golang.org/x/text is out of scope
0 commit comments