2017-04-10 09:30:23 +00:00
|
|
|
package generator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2017-06-13 11:56:07 +00:00
|
|
|
"io/ioutil"
|
2019-02-14 11:47:45 +00:00
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
2017-04-10 09:30:23 +00:00
|
|
|
)
|
|
|
|
|
2019-02-14 11:47:45 +00:00
|
|
|
// Documentation generates regex matchers in Go for documentation files/dirs.
|
|
|
|
// It is of generator.File type.
|
|
|
|
func Documentation(fileToParse, _, outFile, tmplPath, tmplName, commit string) error {
|
2017-06-13 11:56:07 +00:00
|
|
|
data, err := ioutil.ReadFile(fileToParse)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-04-10 09:30:23 +00:00
|
|
|
var regexpList []string
|
|
|
|
if err := yaml.Unmarshal(data, ®expList); err != nil {
|
2017-06-13 11:56:07 +00:00
|
|
|
return err
|
2017-04-10 09:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf := &bytes.Buffer{}
|
2019-02-14 11:47:45 +00:00
|
|
|
err = executeTemplate(buf, tmplName, tmplPath, commit, nil, regexpList)
|
|
|
|
if err != nil {
|
2017-06-13 11:56:07 +00:00
|
|
|
return err
|
2017-04-10 09:30:23 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 11:47:45 +00:00
|
|
|
return formatedWrite(outFile, buf.Bytes())
|
2017-04-10 09:30:23 +00:00
|
|
|
}
|