mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-07-20 12:34:30 -04:00
Update configextractor to support multiple templates
This commit is contained in:
@@ -11,9 +11,13 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
var targets = map[string]string{
|
||||
"extractor.go.tmpl": "output/runner.go",
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Getting relevant packages")
|
||||
paths, err := filepath.Glob("../../*/pkg/config/defaultconfig.go")
|
||||
paths, err := filepath.Glob("../../*/pkg/config/defaults/defaultconfig.go")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -24,27 +28,38 @@ func main() {
|
||||
for i := range paths {
|
||||
paths[i] = replacer.Replace(paths[i])
|
||||
}
|
||||
content, err := ioutil.ReadFile("extractor.go.tmpl")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
for template, output := range targets {
|
||||
GenerateIntermediateCode(template, output, paths)
|
||||
RunIntermediateCode(output)
|
||||
}
|
||||
fmt.Println("Generating intermediate go code")
|
||||
tpl := template.Must(template.New("").Parse(string(content)))
|
||||
os.Mkdir("output", 0700)
|
||||
runner, err := os.Create("output/runner.go")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
tpl.Execute(runner, paths)
|
||||
fmt.Println("Running intermediate go code")
|
||||
os.Chdir("output")
|
||||
os.Setenv("OCIS_BASE_DATA_PATH", "~/.ocis")
|
||||
out, err := exec.Command("go", "run", "runner.go").Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(out))
|
||||
fmt.Println("Cleaning up")
|
||||
os.Chdir("../")
|
||||
os.RemoveAll("output")
|
||||
}
|
||||
|
||||
func GenerateIntermediateCode(templatePath string, intermediateCodePath string, paths []string) {
|
||||
content, err := ioutil.ReadFile(templatePath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println("Generating intermediate go code for " + intermediateCodePath + " using template " + templatePath)
|
||||
tpl := template.Must(template.New("").Parse(string(content)))
|
||||
os.Mkdir("output", 0700)
|
||||
runner, err := os.Create(intermediateCodePath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
tpl.Execute(runner, paths)
|
||||
}
|
||||
|
||||
func RunIntermediateCode(intermediateCodePath string) {
|
||||
fmt.Println("Running intermediate go code for " + intermediateCodePath)
|
||||
os.Chdir("output")
|
||||
os.Setenv("OCIS_BASE_DATA_PATH", "~/.ocis")
|
||||
out, err := exec.Command("go", "run", "../"+intermediateCodePath).Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ m := map[string]interface{}{
|
||||
fields = GetAnnotatedVariables(conf)
|
||||
if len(fields) > 0 {
|
||||
fmt.Printf("... %s\n", pkg)
|
||||
os.MkdirAll(filepath.Join(targetFolder, replacer.Replace(pkg)), 0700)
|
||||
targetFile, err = os.Create(filepath.Join(targetFolder, replacer.Replace(pkg) + "_configvars.md"))
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create target file: %s", err)
|
||||
|
||||
Reference in New Issue
Block a user