feat: input and output file

This commit is contained in:
Justin Lin committed 2025-07-25 02:30:09 +10:00
1 parent 12dcbb460c
commit 3eae45479b
6 files changed
+64 -18

No files matched your search

+19 -1
View File
@@ -1,6 +1,11 @@
package main
import "encoding/json"
import (
"bytes"
"encoding/json"
"fmt"
"text/template"
)
type TemplateMeta struct {
Output string `yaml:"output"`
@@ -15,6 +20,19 @@ func (meta TemplateMeta) String() string {
return string(data)
}
func (meta TemplateMeta) OutputFile(ctx TemplateContext) (output string, err error) {
tmpl, err := template.New("output").Parse(meta.Output)
if err != nil {
return "", fmt.Errorf("Failed to parse output name: %w", err)
}
var buf bytes.Buffer
err = tmpl.Execute(&buf, ctx)
if err != nil {
return "", fmt.Errorf("Failed to execute output name: %w", err)
}
return buf.String(), nil
}
type ParamSpec struct {
Required bool `yaml:"required"`
Default string `yaml:"default"`