config init now leaves out the test sources unless given --all

A section tagged init:"hidden" isn't written to the file config init
generates; fts_mock and sleeper are. config init --all writes them too.
They still load, and the config commands read and set them as before.
This commit is contained in:
bwilliams committed 2026-10-21 16:22:45 +01:00
1 parent f467c6c7da
commit b0f93fd437
8 files changed
+131 -21

No files matched your search

+24
View File
@@ -40,6 +40,30 @@ func LoadDefaultConfig() {
LoadToViper(conf)
}
// InitDefaults returns the default configuration as dotted keys, as
// Flatten gives it, for `config init` to write. Sections tagged
// init:"hidden" (the test sources) are left out unless includeHidden is set.
func InitDefaults(includeHidden bool) map[string]any {
var conf JobSearchConfig
if err := applyDefaults(&conf); err != nil {
panic(fmt.Sprintf("config: %v", err))
}
flat := conf.Flatten()
if includeHidden {
return flat
}
hidden := hiddenFromInitKeys("", reflect.TypeFor[JobSearchConfig]())
for _, section := range hidden {
for key := range flat {
if strings.HasPrefix(key, section+".") {
delete(flat, key)
}
}
}
return flat
}
// ---------- Section methods (see Section) ----------
// Map implements Section.