2024-11-20 09:28:35 +00:00
|
|
|
package template
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"io/fs"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed all:templates
|
|
|
|
var builtinTemplates embed.FS
|
|
|
|
|
2025-01-20 12:09:28 +00:00
|
|
|
// builtinTemplate represents a template that is built into the CLI.
|
|
|
|
type builtinTemplate struct {
|
2024-11-20 09:28:35 +00:00
|
|
|
Name string
|
|
|
|
FS fs.FS
|
|
|
|
}
|
|
|
|
|
2025-01-20 12:09:28 +00:00
|
|
|
// builtin returns the list of all built-in templates.
|
|
|
|
func builtin() ([]builtinTemplate, error) {
|
2024-11-20 09:28:35 +00:00
|
|
|
templates, err := fs.Sub(builtinTemplates, "templates")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
entries, err := fs.ReadDir(templates, ".")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2025-01-20 12:09:28 +00:00
|
|
|
var out []builtinTemplate
|
2024-11-20 09:28:35 +00:00
|
|
|
for _, entry := range entries {
|
|
|
|
if !entry.IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
templateFS, err := fs.Sub(templates, entry.Name())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2025-01-20 12:09:28 +00:00
|
|
|
out = append(out, builtinTemplate{
|
2024-11-20 09:28:35 +00:00
|
|
|
Name: entry.Name(),
|
|
|
|
FS: templateFS,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|