config: Fix doc finding logic
This commit is contained in:
parent
4757b014bc
commit
3f4973cb41
44
node/config/doc_util.go
Normal file
44
node/config/doc_util.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func findDoc(root interface{}, section, name string) *DocField {
|
||||||
|
rt := fmt.Sprintf("%T", root)[len("*config."):]
|
||||||
|
|
||||||
|
doc := findDocSect(rt, section, name)
|
||||||
|
if doc != nil {
|
||||||
|
return doc
|
||||||
|
}
|
||||||
|
|
||||||
|
return findDocSect("Common", section, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func findDocSect(root string, section, name string) *DocField {
|
||||||
|
path := strings.Split(section, ".")
|
||||||
|
|
||||||
|
docSection := Doc[root]
|
||||||
|
for _, e := range path {
|
||||||
|
if docSection == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, field := range docSection {
|
||||||
|
if field.Name == e {
|
||||||
|
docSection = Doc[field.Type]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, df := range docSection {
|
||||||
|
if df.Name == name {
|
||||||
|
return &df
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -86,7 +86,7 @@ func ConfigUpdate(cfgCur, cfgDef interface{}, comment bool) ([]byte, error) {
|
|||||||
nodeLines := strings.Split(nodeStr, "\n")
|
nodeLines := strings.Split(nodeStr, "\n")
|
||||||
var outLines []string
|
var outLines []string
|
||||||
|
|
||||||
sectionRx := regexp.MustCompile(`[\[.]([^.]+)]`)
|
sectionRx := regexp.MustCompile(`\[(.+)]`)
|
||||||
var section string
|
var section string
|
||||||
|
|
||||||
for i, line := range nodeLines {
|
for i, line := range nodeLines {
|
||||||
@ -112,13 +112,7 @@ func ConfigUpdate(cfgCur, cfgDef interface{}, comment bool) ([]byte, error) {
|
|||||||
{
|
{
|
||||||
lf := strings.Fields(line)
|
lf := strings.Fields(line)
|
||||||
if len(lf) > 1 {
|
if len(lf) > 1 {
|
||||||
var doc *DocField
|
doc := findDoc(cfgCur, section, lf[0])
|
||||||
for _, df := range Doc[section] {
|
|
||||||
if df.Name == lf[0] {
|
|
||||||
doc = &df
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if doc != nil {
|
if doc != nil {
|
||||||
// found docfield, emit doc comment
|
// found docfield, emit doc comment
|
||||||
|
Loading…
Reference in New Issue
Block a user