aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/cli.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 15:38:13 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 15:38:13 +0200
commit573aa8bf4677793c6d7da4ef08c79af241aca70e (patch)
tree92846c2852ccdb1e60b1a13ae21b01f6cfc075eb /internal/cli/cli.go
parented7717fef53db3b3aa5593fbb2649313e75a0f31 (diff)
downloadlectio-573aa8bf4677793c6d7da4ef08c79af241aca70e.tar.gz
lectio-573aa8bf4677793c6d7da4ef08c79af241aca70e.zip
cli: --rand -b accepts any version incl. bt (bt falls back to a corpus version instead of erroring); v0.16.1
Diffstat (limited to 'internal/cli/cli.go')
-rw-r--r--internal/cli/cli.go34
1 files changed, 19 insertions, 15 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index ff1299a..04defbf 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -46,7 +46,8 @@ Flags:
--list list all books + abbreviations (dialect from sigla_style)
--citation print the day's gospel reference (scripts/cron) and exit
--week list the coming week's gospel references and exit
- --rand, --rand-v print a random verse (corpus version) and exit
+ --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
-v, --version print the version and exit
-h, --help this help
@@ -710,23 +711,26 @@ func renderCompare(cfg config.Config, list, date string, all, raw bool, width in
return 0
}
-// randVersion picks the corpus version for --rand: an explicit -b VER (rejected
-// if it has no corpus), else the configured default_version if it has a corpus,
-// else the first corpus version in cfg.Versions, else "wuj". So a config whose
-// default is "bt" (no corpus) still yields a random passage.
+// randVersion picks the corpus version for --rand: an explicit -b VER (any of
+// the five is accepted), else the configured default_version. "bt" is allowed
+// but has no embedded corpus (it is the niedziela.pl scrape), so it -- like an
+// unset default -- transparently falls back to the first corpus version in
+// cfg.Versions (else "wuj"), so --rand always yields a passage. Only an unknown
+// version code is an error.
func randVersion(cfg config.Config, bibleVer string) (string, error) {
- if bibleVer != "" {
- if !isCorpusVersion(bibleVer) {
- return "", fmt.Errorf("--rand needs a corpus version; %q has no full text (use wuj, vul, grb, drb)", bibleVer)
- }
- return bibleVer, nil
+ v := bibleVer
+ if v == "" {
+ v = cfg.DefaultVersion
}
- if isCorpusVersion(cfg.DefaultVersion) {
- return cfg.DefaultVersion, nil
+ if v != "" && !config.ValidVersion(v) {
+ return "", fmt.Errorf("unknown version %q (want one of bt, wuj, vul, grb, drb)", v)
}
- for _, v := range cfg.Versions {
- if isCorpusVersion(v) {
- return v, nil
+ if isCorpusVersion(v) {
+ return v, nil
+ }
+ for _, c := range cfg.Versions {
+ if isCorpusVersion(c) {
+ return c, nil
}
}
return "wuj", nil