aboutsummaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go137
-rw-r--r--internal/config/config_test.go39
2 files changed, 122 insertions, 54 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index a9e00d1..31e9078 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -32,9 +32,8 @@ const configHeader = `# lectio configuration (INI). Full-line comments only (# o
#
# Allowed values:
# lectionary new | traditional (new = modern OF; traditional = 1962 EF)
-# traditional_lang pl | en (vernacular for traditional propers)
-# versions any of: bt, wuj, vul, grb, drb (comma list; bt = Biblia TysiÄ…clecia)
-# default_version bt | wuj | vul | grb | drb
+# versions any of: wuj, vul, grb, drb (comma list)
+# default_version wuj | vul | grb | drb
# width integer; 0 = detect terminal width
# all true | false (all readings, or just the gospel)
# offline true | false (never fetch; cache/sigla only)
@@ -46,7 +45,7 @@ const configHeader = `# lectio configuration (INI). Full-line comments only (# o
# web_port integer; 0 = try 1099, then any free port
# web_display horizontal | vertical | interlinear
# web_mono true | false (monospace reading face in the web UI)
-# web_versions any of: bt, wuj, vul, grb, drb (comma list); empty = just default_version
+# web_versions any of: wuj, vul, grb, drb (comma list); empty = just default_version
# pager shell command, e.g. less -R; empty = off
# use calendar layers to stack over the universal calendar: names of
# ~/.config/lectio/calendars/<name>.ini files (comma list, order = precedence)
@@ -65,17 +64,18 @@ const configHeader = `# lectio configuration (INI). Full-line comments only (# o
// -v/--version output (lectio, lectio-ui, lectio-web).
const Version = "0.44.0"
-// validVersions are the five scripture versions lectio understands.
+// validVersions are the scripture versions lectio understands. All are
+// embedded corpora; the former "bt" (the niedziela.pl modern scrape) is gone
+// and a legacy config carrying it is migrated to "wuj" on load (see Load).
var validVersions = map[string]bool{
- "bt": true,
"wuj": true,
"vul": true,
"grb": true,
"drb": true,
}
-// ValidVersion reports whether v is one of the five scripture versions
-// lectio understands (bt, wuj, vul, grb, drb).
+// ValidVersion reports whether v is one of the scripture versions lectio
+// understands (wuj, vul, grb, drb).
func ValidVersion(v string) bool {
return validVersions[v]
}
@@ -150,25 +150,24 @@ func NormalizeSiglaStyle(s string) string {
// Config holds lectio's user-configurable settings. The toml tags are used only
// by the one-shot config.toml -> config.ini migration; the live format is INI.
type Config struct {
- SchemaVersion int `toml:"schema_version"`
- Lectionary string `toml:"lectionary"`
- TraditionalLang string `toml:"traditional_lang"`
- Versions []string `toml:"versions"`
- DefaultVersion string `toml:"default_version"`
- Width int `toml:"width"`
- All bool `toml:"all"`
- Offline bool `toml:"offline"`
- UILanguage string `toml:"ui_language"`
- ReadingLang string `toml:"reading_lang"`
- ReadingVersion string `toml:"reading_version"`
- SiglaStyle string `toml:"sigla_style"`
- WebTheme string `toml:"web_theme"`
- WebPort int `toml:"web_port"`
- WebDisplay string `toml:"web_display"`
- WebMono bool `toml:"web_mono"`
- WebVersions []string `toml:"web_versions"`
- Pager string `toml:"pager"`
- Parts map[string]map[string]bool `toml:"parts"`
+ SchemaVersion int `toml:"schema_version"`
+ Lectionary string `toml:"lectionary"`
+ Versions []string `toml:"versions"`
+ DefaultVersion string `toml:"default_version"`
+ Width int `toml:"width"`
+ All bool `toml:"all"`
+ Offline bool `toml:"offline"`
+ UILanguage string `toml:"ui_language"`
+ ReadingLang string `toml:"reading_lang"`
+ ReadingVersion string `toml:"reading_version"`
+ SiglaStyle string `toml:"sigla_style"`
+ WebTheme string `toml:"web_theme"`
+ WebPort int `toml:"web_port"`
+ WebDisplay string `toml:"web_display"`
+ WebMono bool `toml:"web_mono"`
+ WebVersions []string `toml:"web_versions"`
+ Pager string `toml:"pager"`
+ Parts map[string]map[string]bool `toml:"parts"`
// Computed-calendar placement options (INI [calendar] section; INI-only).
CalEpiphany string `toml:"-"`
@@ -257,23 +256,22 @@ func (c Config) Selection() calendar.Selection {
// is found and as the base that a partial config file overrides.
func Default() Config {
return Config{
- SchemaVersion: 1,
- Lectionary: "new",
- TraditionalLang: "pl",
- Versions: []string{"bt", "wuj", "vul", "grb", "drb"},
- DefaultVersion: "bt",
- Width: 0,
- All: false,
- Offline: false,
- UILanguage: "en",
- SiglaStyle: "auto",
- WebTheme: "transfiguration",
- WebPort: 0,
- WebDisplay: "horizontal",
- WebMono: false,
- WebVersions: nil,
- Pager: "",
- Parts: nil,
+ SchemaVersion: 1,
+ Lectionary: "new",
+ Versions: []string{"wuj", "vul", "grb", "drb"},
+ DefaultVersion: "vul",
+ Width: 0,
+ All: false,
+ Offline: false,
+ UILanguage: "en",
+ SiglaStyle: "auto",
+ WebTheme: "transfiguration",
+ WebPort: 0,
+ WebDisplay: "horizontal",
+ WebMono: false,
+ WebVersions: nil,
+ Pager: "",
+ Parts: nil,
}
}
@@ -471,6 +469,45 @@ func normalize(cfg *Config) {
cfg.WebDisplay = NormalizeDisplay(cfg.WebDisplay)
cfg.UILanguage = NormalizeUILanguage(cfg.UILanguage)
cfg.SiglaStyle = NormalizeSiglaStyle(cfg.SiglaStyle)
+ migrateBT(cfg)
+}
+
+// migrateBT rewrites a legacy "bt" version (the retired niedziela.pl scrape,
+// which had no embedded corpus) to "wuj" wherever a saved config still carries
+// it, so an existing config keeps loading after bt was removed. In a version
+// list "bt" becomes "wuj" only when "wuj" is not already present; otherwise it
+// is dropped, so no list gains a duplicate column.
+func migrateBT(cfg *Config) {
+ if cfg.DefaultVersion == "bt" {
+ cfg.DefaultVersion = "wuj"
+ }
+ cfg.Versions = migrateBTList(cfg.Versions)
+ cfg.WebVersions = migrateBTList(cfg.WebVersions)
+}
+
+func migrateBTList(versions []string) []string {
+ if len(versions) == 0 {
+ return versions
+ }
+ hasWuj := false
+ for _, v := range versions {
+ if v == "wuj" {
+ hasWuj = true
+ break
+ }
+ }
+ out := make([]string, 0, len(versions))
+ for _, v := range versions {
+ if v != "bt" {
+ out = append(out, v)
+ continue
+ }
+ if !hasWuj {
+ out = append(out, "wuj")
+ hasWuj = true
+ }
+ }
+ return out
}
// readINI parses INI bytes into a Config over Default(). Absent keys keep the
@@ -520,8 +557,6 @@ func applyScalar(cfg *Config, key, val string) {
cfg.SchemaVersion = atoiOr(val, cfg.SchemaVersion)
case "lectionary":
cfg.Lectionary = val
- case "traditional_lang":
- cfg.TraditionalLang = val
case "versions":
cfg.Versions = ini.List(val)
case "default_version":
@@ -569,20 +604,17 @@ func validate(cfg Config) error {
if cfg.Lectionary != "new" && cfg.Lectionary != "traditional" {
return fmt.Errorf("config: invalid lectionary %q (must be \"new\" or \"traditional\")", cfg.Lectionary)
}
- if cfg.TraditionalLang != "pl" && cfg.TraditionalLang != "en" {
- return fmt.Errorf("config: invalid traditional_lang %q (must be \"pl\" or \"en\")", cfg.TraditionalLang)
- }
for _, v := range cfg.Versions {
if !validVersions[v] {
- return fmt.Errorf("config: invalid version %q in versions (must be one of bt, wuj, vul, grb, drb)", v)
+ return fmt.Errorf("config: invalid version %q in versions (must be one of wuj, vul, grb, drb)", v)
}
}
if !validVersions[cfg.DefaultVersion] {
- return fmt.Errorf("config: invalid default_version %q (must be one of bt, wuj, vul, grb, drb)", cfg.DefaultVersion)
+ return fmt.Errorf("config: invalid default_version %q (must be one of wuj, vul, grb, drb)", cfg.DefaultVersion)
}
for _, v := range cfg.WebVersions {
if !validVersions[v] {
- return fmt.Errorf("config: invalid version %q in web_versions (must be one of bt, wuj, vul, grb, drb)", v)
+ return fmt.Errorf("config: invalid version %q in web_versions (must be one of wuj, vul, grb, drb)", v)
}
}
return nil
@@ -613,7 +645,6 @@ func renderConfigINI(cfg Config) []byte {
b.WriteString("\n")
fmt.Fprintf(&b, "schema_version = %d\n", cfg.SchemaVersion)
fmt.Fprintf(&b, "lectionary = %s\n", cfg.Lectionary)
- fmt.Fprintf(&b, "traditional_lang = %s\n", cfg.TraditionalLang)
fmt.Fprintf(&b, "versions = %s\n", strings.Join(cfg.Versions, ", "))
fmt.Fprintf(&b, "default_version = %s\n", cfg.DefaultVersion)
fmt.Fprintf(&b, "width = %d\n", cfg.Width)
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 3830cb6..14823b8 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -13,9 +13,20 @@ func TestLoadSeeds(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if cfg.DefaultVersion != "bt" || cfg.Offline {
+ if cfg.DefaultVersion != "vul" || cfg.Offline {
t.Errorf("defaults wrong: %+v", cfg)
}
+ wantVersions := []string{"wuj", "vul", "grb", "drb"}
+ if len(cfg.Versions) != len(wantVersions) {
+ t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions)
+ } else {
+ for i, v := range wantVersions {
+ if cfg.Versions[i] != v {
+ t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions)
+ break
+ }
+ }
+ }
if cfg.Lectionary != "new" {
t.Errorf("lectionary default wrong: %+v", cfg)
}
@@ -24,6 +35,32 @@ func TestLoadSeeds(t *testing.T) {
}
}
+// TestLoadMigratesBT checks a legacy config still carrying the retired "bt"
+// version (both as default_version and in the versions list) loads and is
+// migrated to wuj: bt is dropped from the list when wuj is already present
+// (no duplicate column) and default_version bt becomes wuj.
+func TestLoadMigratesBT(t *testing.T) {
+ dir := t.TempDir()
+ t.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini"))
+ os.WriteFile(filepath.Join(dir, "config.ini"),
+ []byte("default_version = bt\nversions = bt, wuj, vul\n"), 0o644)
+ cfg, err := Load()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if cfg.DefaultVersion != "wuj" {
+ t.Errorf("default_version bt not migrated: %q", cfg.DefaultVersion)
+ }
+ for _, v := range cfg.Versions {
+ if v == "bt" {
+ t.Errorf("versions still carries bt: %v", cfg.Versions)
+ }
+ }
+ if len(cfg.Versions) != 2 || cfg.Versions[0] != "wuj" || cfg.Versions[1] != "vul" {
+ t.Errorf("versions after migration = %v, want [wuj vul]", cfg.Versions)
+ }
+}
+
func TestLoadOverride(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)