Skip to content

Commit

Permalink
Fix: hidden files/directories were not included
Browse files Browse the repository at this point in the history
Files and directories in the template starting with . were not included
anymore after this change:
#14
  • Loading branch information
lfritz committed Feb 28, 2024
1 parent 39510fe commit 9e917b3
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions gootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"text/template"
)

//go:embed templates/*
var templates embed.FS
//go:embed templates/basic/*
var basicTemplate embed.FS

func main() {
name := ""
Expand All @@ -32,18 +32,25 @@ func main() {
os.Exit(1)
}

generate(name, group, templateName)
templates := map[string]embed.FS{
"basic": basicTemplate,
}
templateFS, ok := templates[templateName]
if !ok {
fmt.Println("unknown template:", templateName)
os.Exit(1)
}

generate(name, group, templateFS, path.Join("templates", templateName))
}

func generate(name, group, templateName string) {
func generate(name, group string, templateFS fs.FS, templateDir string) {
type serviceInfo struct {
Name string
Group string
ConfigPrefix string
}

templateDir := path.Join("templates", templateName)

info := serviceInfo{
Name: name,
Group: group,
Expand All @@ -64,7 +71,7 @@ func generate(name, group, templateName string) {
return result.String()
}

err := fs.WalkDir(templates, templateDir, func(path string, d fs.DirEntry, err error) error {
err := fs.WalkDir(templateFS, templateDir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return nil
}
Expand All @@ -83,7 +90,7 @@ func generate(name, group, templateName string) {

log.Printf("generating file %q", targetPath)

data, err := fs.ReadFile(templates, path)
data, err := fs.ReadFile(templateFS, path)
assert(err)

generated := applyTemplate(string(data))
Expand Down

0 comments on commit 9e917b3

Please sign in to comment.