Skip to content

Commit c128476

Browse files
committed
Add an exists template function
From combro2k/docker-gen/3f963a1 Partial support of #19
1 parent edb72a5 commit c128476

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

template.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ import (
1111
"text/template"
1212
)
1313

14+
func exists(path string) (bool, error) {
15+
_, err := os.Stat(path)
16+
if err == nil {
17+
return true, nil
18+
}
19+
if os.IsNotExist(err) {
20+
return false, nil
21+
}
22+
return false, err
23+
}
24+
1425
func groupByMulti(entries []*RuntimeContainer, key, sep string) map[string][]*RuntimeContainer {
1526
groups := make(map[string][]*RuntimeContainer)
1627
for _, v := range entries {
@@ -48,6 +59,7 @@ func generateFile(config Config, containers []*RuntimeContainer) bool {
4859
templatePath := config.Template
4960
tmpl, err := template.New(filepath.Base(templatePath)).Funcs(template.FuncMap{
5061
"contains": contains,
62+
"exists": exists,
5163
"groupBy": groupBy,
5264
"groupByMulti": groupByMulti,
5365
"split": strings.Split,

0 commit comments

Comments
 (0)