package limatmpl
import (
"strings"
"github.com/lima-vm/lima/v2/pkg/limatype"
"github.com/lima-vm/lima/v2/pkg/limayaml"
)
type Template struct {
Locator string
Bytes []byte
Name string
Config *limatype.LimaYAML
expr strings.Builder
}
func (tmpl *Template) ClearOnError(err error) error {
if err != nil {
tmpl.Bytes = nil
tmpl.Config = nil
tmpl.expr.Reset()
}
return err
}
func (tmpl *Template) Unmarshal() error {
if tmpl.Config == nil {
tmpl.Config = &limatype.LimaYAML{}
if err := limayaml.Unmarshal(tmpl.Bytes, tmpl.Config, tmpl.Locator); err != nil {
tmpl.Config = nil
return err
}
}
return nil
}