@@ -5,6 +5,7 @@ package struct_markdown
55
66import (
77 _ "embed"
8+ "fmt"
89 "go/ast"
910 "go/parser"
1011 "go/token"
@@ -121,6 +122,7 @@ func (cmd *Command) Run(args []string) int {
121122 Filename : typeSpec .Name .Name + "-not-required.mdx" ,
122123 }
123124
125+ var hclLabelIndex = 0
124126 for _ , field := range fields {
125127 if len (field .Names ) == 0 || field .Tag == nil {
126128 continue
@@ -161,17 +163,24 @@ func (cmd *Command) Run(args []string) int {
161163 if strings .Contains (docs , "TODO" ) {
162164 continue
163165 }
164- fieldType := string (b [field .Type .Pos ()- 1 : field .Type .End ()- 1 ])
165- fieldType = strings .ReplaceAll (fieldType , "*" , `\*` )
166- switch fieldType {
167- case "time.Duration" :
168- fieldType = `duration string | ex: "1h5m2s"`
169- case "config.Trilean" :
170- fieldType = `boolean`
171- case "config.NameValues" :
172- fieldType = `[]{name string, value string}`
173- case "config.KeyValues" :
174- fieldType = `[]{key string, value string}`
166+
167+ var fieldType string
168+ if hcl , err := tags .Get ("hcl" ); err == nil && hcl .HasOption ("label" ) {
169+ fieldType = fmt .Sprintf (`block label | index: %d` , hclLabelIndex )
170+ hclLabelIndex ++
171+ } else { // Not a label
172+ fieldType = string (b [field .Type .Pos ()- 1 : field .Type .End ()- 1 ])
173+ fieldType = strings .ReplaceAll (fieldType , "*" , `\*` )
174+ switch fieldType {
175+ case "time.Duration" :
176+ fieldType = `duration string | ex: "1h5m2s"`
177+ case "config.Trilean" :
178+ fieldType = `boolean`
179+ case "config.NameValues" :
180+ fieldType = `[]{name string, value string}`
181+ case "config.KeyValues" :
182+ fieldType = `[]{key string, value string}`
183+ }
175184 }
176185
177186 field := Field {
@@ -185,7 +194,7 @@ func (cmd *Command) Run(args []string) int {
185194 continue
186195 }
187196
188- if req , err := tags .Get ("required" ); err == nil && req .Value () == "true" {
197+ if req , err := tags .Get ("required" ); err == nil && req .Name == "true" {
189198 required .Fields = append (required .Fields , field )
190199 } else {
191200 notRequired .Fields = append (notRequired .Fields , field )
0 commit comments