summaryrefslogtreecommitdiff
path: root/internal/cli/cli.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 16:50:45 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 16:50:45 +0200
commit29e244c48222278c2f255ff2adf45e3af7c9f895 (patch)
treeafa11818de1d8115eee1777f7bfc70757f218ac7 /internal/cli/cli.go
parent102bf0c522c94d36f8363c38711621fe5ad18555 (diff)
downloadlectio-29e244c48222278c2f255ff2adf45e3af7c9f895.tar.gz
lectio-29e244c48222278c2f255ff2adf45e3af7c9f895.zip
export: internal/export (Markdown/Text/ReadingsPDF via pure-Go go-pdf/fpdf + embedded DejaVu Sans, covers pl/la/gr); cli --md/--pdf/--out; web /export + download links; v0.22.0
Diffstat (limited to 'internal/cli/cli.go')
-rw-r--r--internal/cli/cli.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index 04defbf..88d3a30 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -16,6 +16,7 @@ import (
"github.com/lukaszkasprzak/lectio/internal/bible"
"github.com/lukaszkasprzak/lectio/internal/config"
+ "github.com/lukaszkasprzak/lectio/internal/export"
"github.com/lukaszkasprzak/lectio/internal/i18n"
"github.com/lukaszkasprzak/lectio/internal/liturgy"
"github.com/lukaszkasprzak/lectio/internal/readings"
@@ -49,6 +50,9 @@ Flags:
--rand, --rand-v print a random verse and exit (uses default_version or -b VER;
bt has no corpus, so it falls back to a corpus version)
--rand-ch print a random chapter and exit
+ --md export the readings as Markdown (to --out or stdout)
+ --pdf export the readings as PDF (to --out or stdout)
+ --out FILE write --md/--pdf output to FILE
-v, --version print the version and exit
-h, --help this help
@@ -107,6 +111,8 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
var all, raw, refresh, offline, update, clean, pagerFlag, noPager, citation, week bool
var randV, randCh bool
+ var expMD, expPDF bool
+ var output string
var bibleVer, compareList, lectionary, lang string
var width int
var list bool
@@ -149,6 +155,10 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
fs.BoolVar(&randV, "rand", false, "print a random verse from the corpus and exit")
fs.BoolVar(&randV, "rand-v", false, "print a random verse from the corpus and exit")
fs.BoolVar(&randCh, "rand-ch", false, "print a random chapter from the corpus and exit")
+ fs.BoolVar(&expMD, "md", false, "export the readings as Markdown")
+ fs.BoolVar(&expPDF, "pdf", false, "export the readings as PDF")
+ fs.StringVar(&output, "out", "", "write --md/--pdf output to FILE (default: stdout)")
+ fs.StringVar(&output, "output", "", "write --md/--pdf output to FILE (default: stdout)")
if err := fs.Parse(rest); err != nil {
return 2
@@ -208,6 +218,18 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
}
effAll := all || cfg.All
+
+ if expMD || expPDF {
+ ver := bibleVer
+ if ver == "" {
+ ver = cfg.DefaultVersion
+ }
+ if !config.ValidVersion(ver) {
+ fmt.Fprintf(stderr, "lectio: unknown version %q (want one of bt, wuj, vul, grb, drb)\n", ver)
+ return 2
+ }
+ return runExport(cfg, date, ver, effAll, refresh, expPDF, output, stdout, stderr)
+ }
effWidth := width
if effWidth == 0 {
effWidth = cfg.Width
@@ -332,6 +354,46 @@ func dialectCitation(cfg config.Config, tbl *bible.BookTable, sec liturgy.Sectio
return tbl.FormatRef(cfg.SiglaLang(), canonical)
}
+// runExport handles --md/--pdf: load the day's readings and write them as
+// Markdown or PDF to --out FILE (or stdout). Honors date/lectionary/all/offline
+// and the version (bt is fine -- it is the niedziela text -- but is swapped for
+// traditional/offline via EffectiveVersions).
+func runExport(cfg config.Config, date, version string, all, refresh, asPDF bool, output string, stdout, stderr io.Writer) int {
+ secs, info, err := readings.Load(cfg, readings.Options{Date: date, Refresh: refresh, Offline: cfg.Offline, All: all})
+ if err != nil {
+ fmt.Fprintln(stderr, "lectio:", err)
+ return 1
+ }
+ if len(secs) == 0 {
+ fmt.Fprintln(stderr, "lectio: no readings found for", date)
+ return 1
+ }
+ if vs := render.EffectiveVersions([]string{version}, cfg.Lectionary, cfg.Offline); len(vs) > 0 {
+ version = vs[0]
+ }
+
+ var data []byte
+ if asPDF {
+ data, err = export.ReadingsPDF(date, info, secs, version, cfg.Lectionary, cfg.UILanguage)
+ if err != nil {
+ fmt.Fprintln(stderr, "lectio:", err)
+ return 1
+ }
+ } else {
+ data = []byte(export.Markdown(date, info, secs, version, cfg.Lectionary, cfg.UILanguage))
+ }
+
+ if output != "" {
+ if err := os.WriteFile(output, data, 0o644); err != nil {
+ fmt.Fprintln(stderr, "lectio:", err)
+ return 1
+ }
+ return 0
+ }
+ _, _ = stdout.Write(data)
+ return 0
+}
+
// runCitation handles --citation: fetch the day's gospel (gospel-only) and
// print just its scripture reference in the configured sigla dialect (see
// dialectCitation), for scripts/cron/prompt use. Honors the resolved cfg