summaryrefslogtreecommitdiff
path: root/internal/cli/cli.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cli/cli.go')
-rw-r--r--internal/cli/cli.go48
1 files changed, 36 insertions, 12 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index 611ce52..31a00ec 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -181,11 +181,12 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
cfg.TraditionalLang = lang
}
- if citation {
- return runCitation(cfg, date, refresh, stdout, stderr)
- }
- if week {
- return runWeek(cfg, date, refresh, stdout, stderr)
+ if citation || week {
+ tbl, _ := bible.LoadBookTable(userBooksTOML())
+ if citation {
+ return runCitation(cfg, tbl, date, refresh, stdout, stderr)
+ }
+ return runWeek(cfg, tbl, date, refresh, stdout, stderr)
}
effAll := all || cfg.All
@@ -291,11 +292,34 @@ func gospelCitation(sec liturgy.Section) string {
return ""
}
+// dialectCitation renders a gospel section's reference in the configured sigla
+// dialect (cfg.SiglaLang(): sigla_style, or -- "auto" -- ui_language). The
+// source citation's language is the lectionary's: Polish for the modern
+// (niedziela) lectionary, cfg.TraditionalLang for the traditional one. The ref
+// is parsed to canonical and re-rendered in the target dialect; a citation
+// whose book can't be parsed comes back in its source form unchanged.
+func dialectCitation(cfg config.Config, tbl *bible.BookTable, sec liturgy.Section) string {
+ raw := gospelCitation(sec)
+ if raw == "" || tbl == nil {
+ return raw
+ }
+ sourceLang := "pl"
+ if cfg.Lectionary == "traditional" {
+ sourceLang = cfg.TraditionalLang
+ }
+ canonical, ok := tbl.ParseRef(sourceLang, raw)
+ if !ok {
+ return raw
+ }
+ return tbl.FormatRef(cfg.SiglaLang(), canonical)
+}
+
// runCitation handles --citation: fetch the day's gospel (gospel-only) and
-// print just its scripture reference, for scripts/cron/prompt use. Honors the
-// resolved cfg (lectionary/lang/offline) and date. Exit 1 if the day has no
-// gospel reference (unpublished date, no network while offline, ...).
-func runCitation(cfg config.Config, date string, refresh bool, stdout, stderr io.Writer) int {
+// print just its scripture reference in the configured sigla dialect (see
+// dialectCitation), for scripts/cron/prompt use. Honors the resolved cfg
+// (lectionary/lang/offline) and date. Exit 1 if the day has no gospel
+// reference (unpublished date, no network while offline, ...).
+func runCitation(cfg config.Config, tbl *bible.BookTable, date string, refresh bool, stdout, stderr io.Writer) int {
secs, _, err := readings.Load(cfg, readings.Options{Date: date, Refresh: refresh, Offline: cfg.Offline, All: false})
if err != nil {
fmt.Fprintln(stderr, "lectio:", err)
@@ -306,7 +330,7 @@ func runCitation(cfg config.Config, date string, refresh bool, stdout, stderr io
fmt.Fprintln(stderr, "lectio: no gospel for", date)
return 1
}
- cit := gospelCitation(sec)
+ cit := dialectCitation(cfg, tbl, sec)
if cit == "" {
fmt.Fprintln(stderr, "lectio: no gospel reference for", date)
return 1
@@ -320,7 +344,7 @@ func runCitation(cfg config.Config, date string, refresh bool, stdout, stderr io
// can't be loaded (unpublished, offline gap, no gospel) shows "—" rather than
// aborting the run, so the list is always seven lines. Honors cfg
// (lectionary/lang/offline).
-func runWeek(cfg config.Config, date string, refresh bool, stdout, stderr io.Writer) int {
+func runWeek(cfg config.Config, tbl *bible.BookTable, date string, refresh bool, stdout, stderr io.Writer) int {
start, err := time.Parse("2006-01-02", date)
if err != nil {
fmt.Fprintln(stderr, "lectio:", err)
@@ -332,7 +356,7 @@ func runWeek(cfg config.Config, date string, refresh bool, stdout, stderr io.Wri
secs, _, err := readings.Load(cfg, readings.Options{Date: d, Refresh: refresh, Offline: cfg.Offline, All: false})
if err == nil {
if sec, ok := gospelSection(secs); ok {
- if c := gospelCitation(sec); c != "" {
+ if c := dialectCitation(cfg, tbl, sec); c != "" {
cit = c
}
}