mirror of
https://github.com/lancatlin/mdsh.git
synced 2026-11-05 19:30:12 +08:00
feat: input and output file
This commit is contained in:
1 parent
12dcbb460c
commit
3eae45479b
6 files changed
+64
-18
No files matched your search
@@ -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"`
|
||||
|
||||
Reference in new issue
Block a user