Browse Source

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>
pull/17/head
John Olheiser 11 months ago
parent
commit
c497431a52
  1. 3
      registry/registry_test.go
  2. 5
      registry/template.go
  3. 7
      registry/template_test.go

3
registry/registry_test.go

@ -98,7 +98,8 @@ func setupTemplate() {
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)
}

5
registry/template.go

@ -85,6 +85,11 @@ func (t *Template) Execute(dest string, defaults, overwrite bool) error {
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

7
registry/template_test.go

@ -72,6 +72,13 @@ func testExecute(t *testing.T) {
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)

Loading…
Cancel
Save