diff options
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 29 | ||||
| -rw-r--r-- | internal/config/config_test.go | 5 |
2 files changed, 32 insertions, 2 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index b6c9e0e..299c942 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -269,13 +269,40 @@ func (c Config) Selection() calendar.Selection { return sel } +// availableVersions lists the corpus codes actually present in this build (the +// embedded Vulgate, plus any compiled in with -tags fullbible or dropped into +// the user corpora dir), Vulgate first then the rest sorted. It keeps the +// default version list coherent with a vul-only binary: an absent corpus is +// never offered by default, so no spurious "(not in wuj)" appears out of the +// box. Users may still name any code explicitly in their config. +func availableVersions() []string { + var rest []string + haveVul := false + for _, m := range bible.Corpora() { + if m.Code == "vul" { + haveVul = true + continue + } + rest = append(rest, m.Code) + } + sort.Strings(rest) + out := rest + if haveVul { + out = append([]string{"vul"}, rest...) + } + if len(out) == 0 { + out = []string{"vul"} // safety: at least the always-embedded Vulgate + } + return out +} + // Default returns lectio's built-in configuration, used when no config file // is found and as the base that a partial config file overrides. func Default() Config { return Config{ SchemaVersion: 1, Lectionary: "new", - Versions: []string{"wuj", "vul", "grb", "drb"}, + Versions: availableVersions(), DefaultVersion: "vul", Width: 0, All: false, diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 14823b8..1035426 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -16,7 +16,10 @@ func TestLoadSeeds(t *testing.T) { if cfg.DefaultVersion != "vul" || cfg.Offline { t.Errorf("defaults wrong: %+v", cfg) } - wantVersions := []string{"wuj", "vul", "grb", "drb"} + // Versions defaults to the corpora actually available in this build, Vulgate + // first then the rest sorted. Tests build with -tags fullbible, so all four + // are present (see Makefile); a default vul-only binary would list just vul. + wantVersions := []string{"vul", "drb", "grb", "wuj"} if len(cfg.Versions) != len(wantVersions) { t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions) } else { |
