aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/cli.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 09:15:40 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 09:15:40 +0200
commitb93de95dd24ff2a1d3126e6d7d00cd77530a03bf (patch)
tree483a0901a20274152ba3f03f272f8098be4f49c0 /internal/cli/cli.go
parentc1b954ad517cef00bf480d5229b253a8c6524be7 (diff)
downloadlectio-b93de95dd24ff2a1d3126e6d7d00cd77530a03bf.tar.gz
lectio-b93de95dd24ff2a1d3126e6d7d00cd77530a03bf.zip
tradlit: offline caching + read; update pre-caches traditional; --clean prunes it; v0.2.0
Diffstat (limited to 'internal/cli/cli.go')
-rw-r--r--internal/cli/cli.go51
1 files changed, 48 insertions, 3 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index c514607..130683c 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -18,6 +18,7 @@ import (
"github.com/lukaszkasprzak/lectio/internal/liturgy"
"github.com/lukaszkasprzak/lectio/internal/readings"
"github.com/lukaszkasprzak/lectio/internal/render"
+ "github.com/lukaszkasprzak/lectio/internal/tradlit"
)
const helpText = `lectio — daily Catholic liturgy readings (Polish + 4 versions)
@@ -241,18 +242,62 @@ func normalizeLectionary(lectionary string) (string, error) {
}
// runHarvest handles -u/--update: harvest sigla maximally (to the
-// unpublished horizon) from date, printing the outcome or -- on a genuine
-// interruption (see liturgy.Harvest) -- the error.
+// unpublished horizon) from date for the modern lectionary, printing the
+// outcome or -- on a genuine interruption (see liturgy.Harvest) -- the
+// error. On a successful harvest it also best-effort pre-caches the
+// traditional lectionary's propers (internal/tradlit) for every date in
+// that same [date, furthest] window, so 'lectio update' prepares both
+// lectionaries for offline use in one run. The 1962 calendar has no
+// "unpublished horizon" (every date has propers), so this is a plain
+// date-range fetch; a per-date failure is not fatal here -- it never
+// prevented the traditional lectionary from working live before, and the
+// modern-harvest outcome is still reported either way.
func runHarvest(date string, stdout, stderr io.Writer) int {
added, furthest, err := liturgy.Harvest(date, 0)
if err != nil {
fmt.Fprintln(stderr, "lectio:", err)
return 1
}
- fmt.Fprintf(stdout, "harvested %d day(s), furthest %s\n", added, furthest)
+
+ lang := config.Default().TraditionalLang
+ cachedTrad := 0
+ if furthest != "" {
+ if cfg, cfgErr := config.Load(); cfgErr == nil {
+ lang = cfg.TraditionalLang
+ cachedTrad = cacheTraditionalRange(date, furthest, lang)
+ }
+ }
+
+ fmt.Fprintf(stdout, "harvested %d day(s), furthest %s; cached traditional propers (%s) for %d day(s)\n",
+ added, furthest, lang, cachedTrad)
return 0
}
+// cacheTraditionalRange best-effort pre-caches tradlit's traditional propers
+// for lang for every date in [from, to] inclusive (walking forward a day at
+// a time), returning how many dates succeeded. A per-date failure (e.g. a
+// transient network hiccup) is ignored -- the traditional 1962 calendar has
+// propers for every date, so there is no "unpublished horizon" to stop at
+// the way liturgy.Harvest has for the modern lectionary.
+func cacheTraditionalRange(from, to, lang string) int {
+ start, err := time.Parse("2006-01-02", from)
+ if err != nil {
+ return 0
+ }
+ end, err := time.Parse("2006-01-02", to)
+ if err != nil {
+ return 0
+ }
+
+ cached := 0
+ for d := start; !d.After(end); d = d.AddDate(0, 0, 1) {
+ if _, err := tradlit.Load(d.Format("2006-01-02"), lang, false); err == nil {
+ cached++
+ }
+ }
+ return cached
+}
+
// runClean handles -C/--clean: prune cached readings older than one year
// (relative to today()) and print a human-readable summary of what was
// removed. Like -u/--update, this is a maintenance mode -- it ignores DATE