Add .tmplkeep #16

Merged
jolheiser merged 1 commits from refs/pull/16/head into main 2021-01-03 03:06:33 +00:00
3 changed files with 14 additions and 1 deletions

View File

@ -98,7 +98,8 @@ func setupTemplate() {
if err := os.MkdirAll(pkgPath, os.ModePerm); err != nil { if err := os.MkdirAll(pkgPath, os.ModePerm); err != nil {
panic(err) panic(err)
} }
fi, err = os.Create(filepath.Join(pkgPath, ".keep")) // .tmplkeep file
fi, err = os.Create(filepath.Join(pkgPath, ".tmplkeep"))
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -85,6 +85,11 @@ func (t *Template) Execute(dest string, defaults, overwrite bool) error {
return err return err
} }
// Skip .tmplkeep files, after creating the directory structure
if strings.EqualFold(walkInfo.Name(), ".tmplkeep") {
return nil
}
oldFi, err := os.Lstat(walkPath) oldFi, err := os.Lstat(walkPath)
if err != nil { if err != nil {
return err return err

View File

@ -72,6 +72,13 @@ func testExecute(t *testing.T) {
t.FailNow() 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 // Change file to test non-overwrite
if err := ioutil.WriteFile(testPath, []byte(tmplNewGold), os.ModePerm); err != nil { if err := ioutil.WriteFile(testPath, []byte(tmplNewGold), os.ModePerm); err != nil {
t.Logf("could not write file: %v\n", err) t.Logf("could not write file: %v\n", err)