diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-27 13:21:04 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-27 13:21:04 +0200 |
| commit | fb3fdc69fad0f374c419559d99d75ba8c81aa632 (patch) | |
| tree | 88be8407988d3eae4366c09884247d656eb7be3b /internal | |
| parent | aaa1c702124a6f0044b458482b349dc725816674 (diff) | |
| download | lectio-fb3fdc69fad0f374c419559d99d75ba8c81aa632.tar.gz lectio-fb3fdc69fad0f374c419559d99d75ba8c81aa632.zip | |
feat(cli): --liturgy uses the config 'use' layer stack (custom calendars take effect)
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/cli/liturgy.go | 7 | ||||
| -rw-r--r-- | internal/cli/liturgy_test.go | 23 |
2 files changed, 29 insertions, 1 deletions
diff --git a/internal/cli/liturgy.go b/internal/cli/liturgy.go index 523531d..fabac48 100644 --- a/internal/cli/liturgy.go +++ b/internal/cli/liturgy.go @@ -23,7 +23,12 @@ func runLiturgy(cfg config.Config, date string, stdout, stderr io.Writer) int { fmt.Fprintf(stderr, "lectio: bad date %q (want YYYY-MM-DD)\n", date) return 2 } - day := calendar.Compute(d.UTC(), cfg.Selection(), []calendar.Layer{caldata.Universal()}) + dir, _ := config.CalendarsDir() + layers, errs := caldata.Stack(dir, cfg.Use) + for _, e := range errs { + fmt.Fprintln(stderr, "lectio: warning:", e) + } + day := calendar.Compute(d.UTC(), cfg.Selection(), layers) printLiturgicalDay(stdout, cfg, day) return 0 } diff --git a/internal/cli/liturgy_test.go b/internal/cli/liturgy_test.go index c3ab0b4..c713703 100644 --- a/internal/cli/liturgy_test.go +++ b/internal/cli/liturgy_test.go @@ -2,6 +2,7 @@ package cli import ( "bytes" + "os" "path/filepath" "strings" "testing" @@ -31,3 +32,25 @@ func TestRunLiturgy(t *testing.T) { t.Errorf("proper reading not shown:\n%s", out) } } + +func TestRunLiturgyUserLayer(t *testing.T) { + dir := t.TempDir() + t.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini")) + // a local layer adds a solemnity on 2025-08-11 (an ordinary Monday), and use it. + os.MkdirAll(filepath.Join(dir, "calendars"), 0o755) + os.WriteFile(filepath.Join(dir, "calendars", "local.ini"), + []byte("[layer]\nid = local\ntype = particular\n\n[patron]\ndate = 08-11\nrank = solemnity\nclass = saint\ncolour = red\nname.en = Local Patron\n"), 0o644) + os.WriteFile(filepath.Join(dir, "config.ini"), []byte("use = local\n"), 0o644) + + cfg, err := config.Load() + if err != nil { + t.Fatal(err) + } + var buf bytes.Buffer + if code := runLiturgy(cfg, "2025-08-11", &buf, &buf); code != 0 { + t.Fatalf("exit %d", code) + } + if !strings.Contains(buf.String(), "Local Patron") { + t.Fatalf("user layer's solemnity not observed:\n%s", buf.String()) + } +} |
