diff --git a/docs/helpers/global_vars.yaml b/docs/helpers/global_vars.yaml index 97af595b8d..71b9d518f2 100644 --- a/docs/helpers/global_vars.yaml +++ b/docs/helpers/global_vars.yaml @@ -1,31 +1,31 @@ variables: - name: CS3_GATEWAY type: "" - default: "" + default_value: "" description: "" dependend_services: [] do_ignore: false - name: CS3_MACHINE_AUTH_API_KEY type: "" - default: "" + default_value: "" description: "" dependend_services: [] do_ignore: false - name: OCIS_BASE_DATA_PATH type: "" - default: "" + default_value: "" description: "" dependend_services: [] do_ignore: false - name: OCIS_CONFIG_DIR type: "" - default: "" + default_value: "" description: "" dependend_services: [] do_ignore: false - name: MICRO_LOG_LEVEL type: "" - default: "" + default_value: "" description: "" dependend_services: [] do_ignore: false diff --git a/docs/helpers/main.go b/docs/helpers/main.go index 08177297b7..86076042c0 100644 --- a/docs/helpers/main.go +++ b/docs/helpers/main.go @@ -3,4 +3,5 @@ package main func main() { RenderTemplates() GetRogueEnvs() + RenderGlobalVarsTemplate() } diff --git a/docs/helpers/rogueEnv.go b/docs/helpers/rogueEnv.go index c05625c431..28eab2d493 100644 --- a/docs/helpers/rogueEnv.go +++ b/docs/helpers/rogueEnv.go @@ -9,6 +9,7 @@ import ( "path/filepath" "regexp" "strings" + "text/template" "gopkg.in/yaml.v2" ) @@ -22,7 +23,7 @@ type ConfigVars struct { type Variable struct { Name string `yaml:"name"` Type string `yaml:"type"` - Default string `yaml:"default"` + DefaultValue string `yaml:"default_value"` Description string `yaml:"description"` DependendServices []Service `yaml:"dependend_services"` DoIgnore bool `yaml:"do_ignore"` @@ -46,7 +47,7 @@ func GetRogueEnvs() { if err == nil { err := yaml.Unmarshal(yfile, &vars) if err != nil { - log.Fatalf("could not unmarshall %s", fullYamlPath) + log.Fatal(err) } } @@ -90,3 +91,40 @@ func AddUniqueToStruct(variables *ConfigVars, variable Variable) { } variables.Variables = append(variables.Variables, variable) } + +func RenderGlobalVarsTemplate() { + curdir, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + fullYamlPath := filepath.Join(curdir, yamlSource) + + content, err := ioutil.ReadFile("../../docs/templates/ADOC_global.tmpl") + if err != nil { + log.Fatal(err) + } + + targetFolder := "../../docs/services/_includes/adoc/" + + vars := &ConfigVars{} + fmt.Printf("Reading existing variable definitions from %s\n", fullYamlPath) + yfile, err := ioutil.ReadFile(fullYamlPath) + if err != nil { + log.Fatal(err) + } + err = yaml.Unmarshal(yfile, &vars) + if err != nil { + log.Fatal(err) + } + + targetFile, err := os.Create(filepath.Join(targetFolder, "global_configvars.adoc")) + if err != nil { + log.Fatalf("Failed to create target file: %s", err) + } + defer targetFile.Close() + + tpl := template.Must(template.New("").Parse(string(content))) + if err = tpl.Execute(targetFile, *vars); err != nil { + log.Fatalf("Failed to execute template: %s", err) + } +} diff --git a/docs/templates/ADOC_global.tmpl b/docs/templates/ADOC_global.tmpl new file mode 100644 index 0000000000..dca1dd9988 --- /dev/null +++ b/docs/templates/ADOC_global.tmpl @@ -0,0 +1,23 @@ +// set the attribute to true or leave empty, true without any quotes. + +[caption=] +.Global environment Variables +[width="100%",cols="~,~,~,~",options="header"] +| === | +| Name | +| Type | +| Default Value | +| Description | + +{{- range .Variables}} + +a| `{{- .Name }}` + +a| [subs=-attributes] +++{{ .Type }} ++ +a| [subs=-attributes] +++{{.DefaultValue}} ++ +a| [subs=-attributes] +{{.Description}} + +{{- end }} +| === |