aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/cli.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 23:45:07 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 23:45:07 +0200
commitc1b954ad517cef00bf480d5229b253a8c6524be7 (patch)
tree376a281de7604782722d5780657aff319c32a1d6 /internal/cli/cli.go
parent369c995292b0ae830e077c5845f0b09fbe3508a4 (diff)
downloadlectio-c1b954ad517cef00bf480d5229b253a8c6524be7.tar.gz
lectio-c1b954ad517cef00bf480d5229b253a8c6524be7.zip
cli-ui,web: real flag parsing for lectio-ui/lectio-web (accept useful flags, reject unknown, -h/-v)
Diffstat (limited to 'internal/cli/cli.go')
-rw-r--r--internal/cli/cli.go34
1 files changed, 11 insertions, 23 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index 720c165..c514607 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -20,9 +20,6 @@ import (
"github.com/lukaszkasprzak/lectio/internal/render"
)
-// versionString is printed by --version/-v.
-const versionString = "0.1.0"
-
const helpText = `lectio — daily Catholic liturgy readings (Polish + 4 versions)
Usage:
@@ -65,14 +62,6 @@ const (
var dateRe = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}$`)
-var validVersions = map[string]bool{
- "pl": true,
- "wuj": true,
- "vul": true,
- "grb": true,
- "drb": true,
-}
-
func today() string {
return time.Now().Format("2006-01-02")
}
@@ -84,7 +73,7 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
return 0
}
if wantsVersion(args) {
- fmt.Fprintln(stdout, "lectio "+versionString)
+ fmt.Fprintln(stdout, "lectio "+config.Version)
return 0
}
if len(args) > 0 && args[0] == "help" {
@@ -179,7 +168,7 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
return renderCompare(cfg, compareList, date, effAll, raw, effWidth, refresh, stdout, stderr)
}
if bibleVer != "" {
- if !validVersions[bibleVer] {
+ if !config.ValidVersion(bibleVer) {
fmt.Fprintf(stderr, "lectio: unknown version %q (want one of pl, wuj, vul, grb, drb)\n", bibleVer)
return 2
}
@@ -237,19 +226,18 @@ func extractDate(args []string) (date string, rest []string, err error) {
// normalizeLectionary maps -l/--lectionary's accepted spellings ("new",
// "trad", "traditional") onto the canonical config.Config.Lectionary values
-// ("new", "traditional"); "" (flag not given) passes through unchanged so
-// the caller knows to leave config's own setting alone.
+// ("new", "traditional") via config.NormalizeLectionary; "" (flag not given)
+// passes through unchanged so the caller knows to leave config's own
+// setting alone.
func normalizeLectionary(lectionary string) (string, error) {
- switch lectionary {
- case "":
+ if lectionary == "" {
return "", nil
- case "trad":
- return "traditional", nil
- case "new", "traditional":
- return lectionary, nil
- default:
+ }
+ v, ok := config.NormalizeLectionary(lectionary)
+ if !ok {
return "", fmt.Errorf("invalid --lectionary %q (want new|trad)", lectionary)
}
+ return v, nil
}
// runHarvest handles -u/--update: harvest sigla maximally (to the
@@ -397,7 +385,7 @@ func renderCompare(cfg config.Config, list, date string, all, raw bool, width in
}
}
for _, v := range versions {
- if !validVersions[v] {
+ if !config.ValidVersion(v) {
fmt.Fprintf(stderr, "lectio: unknown version %q (want one of pl, wuj, vul, grb, drb)\n", v)
return 2
}