mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-12 22:42:23 +00:00
7eafe024af
Signed-off-by: Denys Smirnov <denys@sourced.tech>
33 lines
817 B
Go
33 lines
817 B
Go
package generator
|
|
|
|
import (
|
|
"bytes"
|
|
"gopkg.in/yaml.v2"
|
|
"io"
|
|
"io/ioutil"
|
|
)
|
|
|
|
// Vendor reads from fileToParse and builds source file from tmplPath. It complies with type File signature.
|
|
func Vendor(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
|
data, err := ioutil.ReadFile(fileToParse)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var regexpList []string
|
|
if err := yaml.Unmarshal(data, ®expList); err != nil {
|
|
return nil
|
|
}
|
|
|
|
buf := &bytes.Buffer{}
|
|
if err := executeVendorTemplate(buf, regexpList, tmplPath, tmplName, commit); err != nil {
|
|
return nil
|
|
}
|
|
|
|
return formatedWrite(outPath, buf.Bytes())
|
|
}
|
|
|
|
func executeVendorTemplate(out io.Writer, regexpList []string, tmplPath, tmplName, commit string) error {
|
|
return executeTemplate(out, tmplName, tmplPath, commit, nil, regexpList)
|
|
}
|