parent
48f0436954
commit
613d1706d8
50
magefile.go
50
magefile.go
|
@ -740,7 +740,7 @@ type configOption struct {
|
||||||
children []*configOption
|
children []*configOption
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseYamlNode(node *yaml.Node) (config *configOption) {
|
func parseYamlConfigNode(node *yaml.Node) (config *configOption) {
|
||||||
config = &configOption{
|
config = &configOption{
|
||||||
key: node.Value,
|
key: node.Value,
|
||||||
description: node.HeadComment,
|
description: node.HeadComment,
|
||||||
|
@ -765,7 +765,7 @@ func parseYamlNode(node *yaml.Node) (config *configOption) {
|
||||||
|
|
||||||
if len(n2.Content) > 0 {
|
if len(n2.Content) > 0 {
|
||||||
for _, n := range n2.Content {
|
for _, n := range n2.Content {
|
||||||
coo.children = append(coo.children, parseYamlNode(n))
|
coo.children = append(coo.children, parseYamlConfigNode(n))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -773,6 +773,27 @@ func parseYamlNode(node *yaml.Node) (config *configOption) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printConfig(config []*configOption, level int) (rendered string) {
|
||||||
|
for _, option := range config {
|
||||||
|
if option.key != "" {
|
||||||
|
|
||||||
|
for i := 0; i <= level; i++ {
|
||||||
|
rendered += "#"
|
||||||
|
}
|
||||||
|
rendered += " " + option.key + "\n"
|
||||||
|
|
||||||
|
if option.description != "" {
|
||||||
|
rendered += "\n\n" + option.description + "\n\n"
|
||||||
|
}
|
||||||
|
rendered += "Default: `" + option.defaultValue + "`\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
rendered += "\n" + printConfig(option.children, level+1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Generates the error docs from a commented config.yml.sample file in the repo root.
|
// Generates the error docs from a commented config.yml.sample file in the repo root.
|
||||||
func GenerateDocs() error {
|
func GenerateDocs() error {
|
||||||
|
|
||||||
|
@ -791,33 +812,12 @@ func GenerateDocs() error {
|
||||||
|
|
||||||
for _, node := range d.Content {
|
for _, node := range d.Content {
|
||||||
for _, n := range node.Content {
|
for _, n := range node.Content {
|
||||||
co := parseYamlNode(n)
|
co := parseYamlConfigNode(n)
|
||||||
conf = append(conf, co)
|
conf = append(conf, co)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, option := range conf {
|
fmt.Println(printConfig(conf, 0))
|
||||||
if option.key != "" {
|
|
||||||
fmt.Printf("Option: %s\n", option.key)
|
|
||||||
|
|
||||||
if option.description != "" {
|
|
||||||
fmt.Printf("Description: %s\n", option.description)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, child := range option.children {
|
|
||||||
if child.key != "" {
|
|
||||||
|
|
||||||
// TODO: Add generating docs from recursive structure
|
|
||||||
|
|
||||||
fmt.Printf("[Child] Option: %s, Default: %s\n", child.key, child.defaultValue)
|
|
||||||
|
|
||||||
if child.description != "" {
|
|
||||||
fmt.Printf("[Child] Description: %s\n", child.description)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue