tmpl @main -
refs -
log -
-
https://git.jolheiser.com/tmpl.git
Template automation
Add .tmplkeep (#16)
Resolves #15
Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: https://gitea.com/jolheiser/tmpl/pulls/16
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-committed-by: John Olheiser <john.olheiser@gmail.com>
3 changed files, 14 additions(+), 1 deletions(-)
diff --git a/registry/registry_test.go b/registry/registry_test.go
index 8adc7ca075829844fd7923247675985c85ee096b..628e29dc09b5359e0650526c7661837a9a477384 100644
--- a/registry/registry_test.go
+++ b/registry/registry_test.go
@@ -98,7 +98,8 @@ pkgPath := filepath.Join(tmplDir, "template", "{{upper package}}")
if err := os.MkdirAll(pkgPath, os.ModePerm); err != nil {
panic(err)
}
- fi, err = os.Create(filepath.Join(pkgPath, ".keep"))
+ // .tmplkeep file
+ fi, err = os.Create(filepath.Join(pkgPath, ".tmplkeep"))
if err != nil {
panic(err)
}
diff --git a/registry/template.go b/registry/template.go
index 938eff00500886ee1f3a222fd07cb432318d40b6..76bf84c425959dc4e15facc9726d9a22ba620ca5 100644
--- a/registry/template.go
+++ b/registry/template.go
@@ -85,6 +85,11 @@ if err := os.MkdirAll(filepath.Dir(newDest), os.ModePerm); err != nil {
return err
}
+ // Skip .tmplkeep files, after creating the directory structure
+ if strings.EqualFold(walkInfo.Name(), ".tmplkeep") {
+ return nil
+ }
+
oldFi, err := os.Lstat(walkPath)
if err != nil {
return err
diff --git a/registry/template_test.go b/registry/template_test.go
index dd8c317c860422481d6a0c7b3ff6e995b12fc3ce..a51717be1396de93d93f661ffb6b77aafad1bf12 100644
--- a/registry/template_test.go
+++ b/registry/template_test.go
@@ -72,6 +72,13 @@ t.Logf("expected a directory at %s: %v\n", pkgPath, err)
t.FailNow()
}
+ // Check for .tmplkeep
+ tmplKeep := filepath.Join(pkgPath, ".tmplkeep")
+ if _, err := os.Lstat(tmplKeep); err == nil {
+ t.Logf(".tmplkeep files should NOT be retained upon execution: %s\n", tmplKeep)
+ t.FailNow()
+ }
+
// Change file to test non-overwrite
if err := ioutil.WriteFile(testPath, []byte(tmplNewGold), os.ModePerm); err != nil {
t.Logf("could not write file: %v\n", err)