diff options
Diffstat (limited to 'internal/cli/cli.go')
| -rw-r--r-- | internal/cli/cli.go | 34 |
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 |
