aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/cli/cli.go24
-rw-r--r--internal/render/render.go13
-rw-r--r--internal/tui/tui.go5
-rw-r--r--internal/web/server.go7
4 files changed, 31 insertions, 18 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index 5c05713..38de4c1 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -83,7 +83,7 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
fmt.Fprint(stdout, helpText)
return 0
}
- if len(args) > 0 && (args[0] == "--version" || args[0] == "-v") {
+ if wantsVersion(args) {
fmt.Fprintln(stdout, "lectio "+versionString)
return 0
}
@@ -198,6 +198,18 @@ func wantsHelp(args []string) bool {
return false
}
+// wantsVersion reports whether -v/--version appears anywhere in args (like
+// wantsHelp), so `lectio DATE -v` prints the version rather than erroring on
+// an "undefined flag".
+func wantsVersion(args []string) bool {
+ for _, a := range args {
+ if a == "-v" || a == "--version" {
+ return true
+ }
+ }
+ return false
+}
+
// extractDate pulls the single positional DATE token (YYYY-MM-DD, matching
// dateRe) out of args, wherever it appears, and returns it along with the
// remaining tokens for flag.FlagSet to parse. No flag's own value can match
@@ -315,10 +327,8 @@ func fetchAndPrint(cfg config.Config, version, date string, all, raw bool, width
return 1
}
- if cfg.Offline {
- if vs := render.OfflineVersions([]string{version}); len(vs) > 0 {
- version = vs[0]
- }
+ if vs := render.EffectiveVersions([]string{version}, cfg.Lectionary, cfg.Offline); len(vs) > 0 {
+ version = vs[0]
}
w := resolveWidth(width, false, stdout)
@@ -395,9 +405,7 @@ func renderCompare(cfg config.Config, list, date string, all, raw bool, width in
return 2
}
}
- if cfg.Offline {
- versions = render.OfflineVersions(versions)
- }
+ versions = render.EffectiveVersions(versions, cfg.Lectionary, cfg.Offline)
secs, err := readings.Load(cfg, readings.Options{
Date: date,
diff --git a/internal/render/render.go b/internal/render/render.go
index 6bccc65..265ed18 100644
--- a/internal/render/render.go
+++ b/internal/render/render.go
@@ -225,6 +225,19 @@ func OfflineVersions(versions []string) []string {
return out
}
+// EffectiveVersions is the version set actually loadable for a request: "pl"
+// (the niedziela.pl modern scrape) is dropped -- substituting "wuj" if it was
+// the only Polish column, via OfflineVersions -- whenever the scrape is
+// unavailable: offline (never fetch) OR the traditional lectionary
+// (missalemeum, which has no niedziela.pl scrape). Shared by cli, tui and web
+// so all three binaries treat traditional/offline versions identically.
+func EffectiveVersions(versions []string, lectionary string, offline bool) []string {
+ if offline || lectionary == "traditional" {
+ return OfflineVersions(versions)
+ }
+ return versions
+}
+
// Compare lays the versions of one reading section out as parallel columns,
// side by side, wrapped to fit width. Ports render_compare. lang selects the
// column-header label language (see GatherVersion).
diff --git a/internal/tui/tui.go b/internal/tui/tui.go
index bcfb3c1..06ad19f 100644
--- a/internal/tui/tui.go
+++ b/internal/tui/tui.go
@@ -49,10 +49,7 @@ type errMsg struct {
// "" if there are none), and the date starts at today. The first fetch is
// issued by Init, not here.
func New(cfg config.Config) Model {
- versions := append([]string(nil), cfg.Versions...)
- if cfg.Offline {
- versions = render.OfflineVersions(versions)
- }
+ versions := render.EffectiveVersions(append([]string(nil), cfg.Versions...), cfg.Lectionary, cfg.Offline)
idx := indexOf(versions, cfg.DefaultVersion)
if idx < 0 {
diff --git a/internal/web/server.go b/internal/web/server.go
index 4c13576..3a7517a 100644
--- a/internal/web/server.go
+++ b/internal/web/server.go
@@ -159,12 +159,7 @@ func resolveQuery(cfg config.Config, r *http.Request) (date, lectionary string,
// always match what was actually loadable.
func loadSections(cfg config.Config, lectionary, date string, all bool, versions []string) ([]liturgy.Section, []string, error) {
cfg.Lectionary = lectionary
- if cfg.Offline {
- versions = render.OfflineVersions(versions)
- }
- if lectionary == "traditional" {
- versions = render.OfflineVersions(versions)
- }
+ versions = render.EffectiveVersions(versions, lectionary, cfg.Offline)
secs, err := readings.Load(cfg, readings.Options{
Date: date,
Offline: cfg.Offline,