Skip to content

Commit 91f7dd9

Browse files
support multiple config sections in json format
1 parent 10f40a6 commit 91f7dd9

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

_examples/simple/doc.json

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
[
22
{
3-
"env_name": "HOST",
4-
"doc": "Hosts name of hosts to listen on.",
5-
"env_separator": ";",
6-
"required": true
7-
},
8-
{
9-
"env_name": "PORT",
10-
"doc": "Port to listen on.",
11-
"required": true,
12-
"non_empty": true
13-
},
14-
{
15-
"env_name": "DEBUG",
16-
"doc": "Debug mode enabled.",
17-
"env_default": "false"
18-
},
19-
{
20-
"env_name": "PREFIX",
21-
"doc": "Prefix for something."
3+
"name": "Config",
4+
"doc": "Config is an example configuration structure.\nIt is used to generate documentation for the configuration\nusing the commands below.",
5+
"items": [
6+
{
7+
"env_name": "HOST",
8+
"doc": "Hosts name of hosts to listen on.",
9+
"env_separator": ";",
10+
"required": true
11+
},
12+
{
13+
"env_name": "PORT",
14+
"doc": "Port to listen on.",
15+
"required": true,
16+
"non_empty": true
17+
},
18+
{
19+
"env_name": "DEBUG",
20+
"doc": "Debug mode enabled.",
21+
"env_default": "false"
22+
},
23+
{
24+
"env_name": "PREFIX",
25+
"doc": "Prefix for something."
26+
}
27+
]
2228
}
2329
]

render/renderer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ func (r *Renderer) Render(scopes []*types.EnvScope, out io.Writer) error {
3535
}
3636

3737
type renderSection struct {
38-
Name string
39-
Doc string
40-
Items []renderItem
38+
Name string `json:"name,omitempty"`
39+
Doc string `json:"doc,omitempty"`
40+
Items []renderItem `json:"items,omitempty"`
4141
}
4242

4343
type renderItem struct {

render/templ/json.tmpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{{- range .Sections }}
2-
{{- marshalIndent .Items }}
3-
{{- end }}
1+
{{- marshalIndent .Sections }}

0 commit comments

Comments
 (0)