mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-14 15:32:24 +00:00
3499750785
Sync \w Github Linguist v7.2.0 Includes new way of handling `heuristics.yml` and all `./data/*` re-generated using Github Linguist [v7.2.0](https://github.com/github/linguist/releases/tag/v7.2.0) release tag. - many new languages - better vendoring detection - update doc on update&known issues.
35 lines
809 B
Go
35 lines
809 B
Go
package generator
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"io/ioutil"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
// Vendor generates regex matchers in Go for vendoring files/dirs.
|
|
// It is of generator.File type.
|
|
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)
|
|
}
|