cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

main
012 / internal / config / docs.go
docs.go 2.1K
1package config23import (4 "fmt"5 "strings"6)78// DocsMarker divides docs/reference/config.md: the introduction above it is9// written by hand, the reference below it is Reference's output.10const DocsMarker = "<!-- Generated from internal/config/registry.go by `go test ./internal/config -update-docs`. Don't edit below. -->"1112// Reference is the option reference in Markdown, one section per group.13func Reference() string {14 var b strings.Builder15 overview(&b)16 for _, g := range Groups {17 fmt.Fprintf(&b, "\n### %s\n", g)18 for _, o := range Options {19 if o.Group != g {20 continue21 }22 fmt.Fprintf(&b, "\n#### `%s`\n\n%s\n\n", o.Name, o.Desc)23 b.WriteString("| | |\n|---|---|\n")24 fmt.Fprintf(&b, "| Type | %s |\n", o.typeDoc())25 def := "(empty)"26 if o.Default != "" {27 def = "`" + o.Default + "`"28 }29 fmt.Fprintf(&b, "| Default | %s |\n", def)30 if len(o.Env) > 0 {31 fmt.Fprintf(&b, "| Environment | `%s` |\n", strings.Join(o.Env, "`, `"))32 }33 if len(o.Fallback) > 0 {34 fmt.Fprintf(&b, "| When unset | `%s` |\n", strings.Join(o.Fallback, "`, `"))35 }36 if o.Flag != "" {37 fmt.Fprintf(&b, "| Flag | `%s` |\n", o.Flag)38 }39 if o.Repeat {40 b.WriteString("| Repeatable | yes |\n")41 }42 reload := "restart 012"43 if o.Live {44 reload = "File > Settings > Reload config"45 }46 fmt.Fprintf(&b, "| Applies | %s |\n", reload)47 }48 }49 return b.String()50}5152func (o *Option) typeDoc() string {53 if o.Kind == Enum {54 return "one of `" + strings.Join(o.Values, "`, `") + "`"55 }56 return o.Kind.String()57}5859// overview is a table of every option, its default and where else it's60// set, linking to its section.61func overview(b *strings.Builder) {62 b.WriteString("\n| Option | Default | Environment, flag |\n|---|---|---|\n")63 for _, g := range Groups {64 for _, o := range Options {65 if o.Group != g {66 continue67 }68 def := ""69 if o.Default != "" {70 def = "`" + o.Default + "`"71 }72 var via []string73 for _, e := range o.Env {74 via = append(via, "`"+e+"`")75 }76 if o.Flag != "" {77 via = append(via, "`"+o.Flag+"`")78 }79 fmt.Fprintf(b, "| [`%s`](#%s) | %s | %s |\n", o.Name, o.Name, def, strings.Join(via, ", "))80 }81 }82}