aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/cli.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cli/cli.go')
-rw-r--r--internal/cli/cli.go24
1 files changed, 16 insertions, 8 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,