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
parent
d4c47101ab
commit
c497431a52
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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…
Reference in New Issue