Skip to content

Commit e7f8225

Browse files
stevenvegtreinkrul
andauthored
docs: generate server options as list-table for stable diffs (#4426)
* docs: generate server options as list-table for stable diffs The simple-table format pads every cell to the widest value in its column, so a single new option with a long description rewrites the entire table (as happened in #4420, where 2 new options produced a 142-line diff). A list-table has no cross-row alignment: adding an option is always a 3-line diff. The rendered HTML is identical, verified by diffing Sphinx output of both formats. Also removes a stray debug println from the generator. Assisted-by: AI * build: add docs-docker Makefile target for containerized Sphinx builds The docs/Dockerfile existed but nothing referenced it. The new target builds the documentation without requiring Python/Sphinx on the host. Assisted-by: AI --------- Co-authored-by: Rein Krul <info@reinkrul.nl>
1 parent f8c82d1 commit e7f8225

6 files changed

Lines changed: 409 additions & 169 deletions

File tree

docs/generate_docs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ func extractFlagsForEngine(flagSet *pflag.FlagSet, config interface{}, engineNam
178178
}
179179

180180
flagSet.VisitAll(func(current *pflag.Flag) {
181-
println(current.Name, engineName)
182181
if current.Name == engineName ||
183182
strings.HasPrefix(current.Name, engineName+".") {
184183
// This flag belongs to this engine, so copy it and hide it in the input flag set
@@ -248,9 +247,10 @@ func generateRstTable(tableName, fileName string, values [][]rstValue) {
248247
panic(err)
249248
}
250249
defer optionsFile.Close()
251-
optionsFile.WriteString(fmt.Sprintf(".. table:: %s\n", tableName))
250+
optionsFile.WriteString(fmt.Sprintf(".. list-table:: %s\n", tableName))
252251
optionsFile.WriteString(" :widths: 20 30 50\n")
253-
optionsFile.WriteString(" :class: options-table\n\n")
252+
optionsFile.WriteString(" :class: options-table\n")
253+
optionsFile.WriteString(" :header-rows: 1\n\n")
254254
printRstTable(vals("Key", "Default", "Description"), values, optionsFile)
255255
if err := optionsFile.Sync(); err != nil {
256256
panic(err)

docs/generate_docs_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,36 @@ package main
2020

2121
import (
2222
"sort"
23+
"strings"
2324
"testing"
2425
)
2526

27+
func TestPrintRstTable(t *testing.T) {
28+
var buf strings.Builder
29+
printRstTable(vals("Key", "Default", "Description"), [][]rstValue{
30+
{{value: "HTTP", bold: true}},
31+
vals("http.public.address", ":8080", "Public address"),
32+
vals("cpuprofile", "", "CPU profile path"),
33+
}, &buf)
34+
35+
expected := ` * - Key
36+
- Default
37+
- Description
38+
* - **HTTP**
39+
-
40+
-
41+
* - http.public.address
42+
- \:8080
43+
- Public address
44+
* - cpuprofile
45+
-
46+
- CPU profile path
47+
`
48+
if buf.String() != expected {
49+
t.Errorf("unexpected list-table output:\ngot:\n%s\nwant:\n%s", buf.String(), expected)
50+
}
51+
}
52+
2653
func TestKeyList(t *testing.T) {
2754
got := KeyList{
2855
[]rstValue{{value: "storage.bbolt.backup.directory"}},

0 commit comments

Comments
 (0)