From ea43e20f25283cb3514df2f3276f74501742ded8 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Wed, 14 May 2025 09:07:28 -0500 Subject: [PATCH] pkg/config/configtest: DocDefaultsOnly ignore arrays of tables --- pkg/config/configtest/defaults.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/config/configtest/defaults.go b/pkg/config/configtest/defaults.go index d0535a8529..62b605e616 100644 --- a/pkg/config/configtest/defaults.go +++ b/pkg/config/configtest/defaults.go @@ -10,6 +10,7 @@ import ( // DocDefaultsOnly reads only the default values from a docs TOML file and decodes in to cfg. // Fields without defaults will set to zero values. +// Arrays of tables are ignored. func DocDefaultsOnly(r io.Reader, cfg any, decode func(io.Reader, any) error) error { pr, pw := io.Pipe() defer pr.Close() @@ -26,12 +27,25 @@ func DocDefaultsOnly(r io.Reader, cfg any, decode func(io.Reader, any) error) er func writeDefaults(r io.Reader, w *io.PipeWriter) { defer w.Close() s := bufio.NewScanner(r) + var skipUntil func(line string) bool for s.Scan() { t := s.Text() + if skipUntil != nil { + if skipUntil(t) { + skipUntil = nil + } + continue + } // Skip comments and examples (which become zero values) if strings.HasPrefix(t, "#") || strings.HasSuffix(t, "# Example") { continue } + // Skip arrays of tables + if strings.HasPrefix(t, "[[") { + // skip fields until next empty line + skipUntil = func(line string) bool { return strings.TrimSpace(line) == "" } + continue + } if _, err := io.WriteString(w, t); err != nil { w.CloseWithError(err) }