all repos — bibel @ e1af2a303bdda6481749d7e22e1fbeab687562ac

Unnamed repository; edit this file 'description' to name the repository.

fix: correct reading mode validation syntax error and clean up formatter

- Fix misplaced closing brace in `cmd/bibel.go` that prevented
  `-r/--reading` flag from taking effect
  - Move reading mode validation inside the conditional block after
    command line override
  - Add validation for `evangelion`, `new_testament`, `old_testament`,
    `bible` values with clear error message
- Update `cmd/bibel.go` to use `NewDateProgressionWithReadingMode` with
  proper reading mode from config
- Refactor `internal/formatter.go` to use `fmt.Fprintf` instead of
  `fmt.Sprintf` for numbered verse output (consistent with io.Writer)
- Remove duplicate `max` function from `formatter.go` (already exists
  elsewhere or unused)
- Normalise whitespace and blank lines in formatter code for consistency
- Update `CHANGELOG.md` with version 1.0.1 entry describing the syntax
  error fix
Maxwell Jensen 85795372+maxwelljens@users.noreply.github.com
Mon, 20 Apr 2026 08:38:37 +0200
commit

e1af2a303bdda6481749d7e22e1fbeab687562ac

parent

e9564eeb1c77bbaf7e5bbdff4aec44a2f486d6e2

3 files changed, 39 insertions(+), 24 deletions(-)

jump to
M CHANGELOG.mdCHANGELOG.md

@@ -8,6 +8,14 @@ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] +## [1.0.1] - 2026-04-20 + +### Fixed + +- Fixed syntax error in `cmd/bibel.go` where closing brace for reading mode +validation was misplaced, preventing `-r/--reading` command line option from +taking effect + ## [1.0.0] - 2026-04-18 ### Added
M cmd/bibel.gocmd/bibel.go

@@ -61,6 +61,18 @@

// Override reading mode from command line if specified if args.Reading != "" { config.ReadingMode = args.Reading + + // Validate reading mode after command line override + validReadingModes := map[string]bool{ + "evangelion": true, + "new_testament": true, + "old_testament": true, + "bible": true, + } + if config.ReadingMode != "" && !validReadingModes[config.ReadingMode] { + fmt.Fprintf(os.Stderr, "Error: invalid reading mode: %s, must be one of: evangelion, new_testament, old_testament, bible\n", config.ReadingMode) + os.Exit(1) + } } // Load Bible data

@@ -73,7 +85,8 @@

// Create date progression calculator // We need to convert reading mode string to ReadingMode type // Based on verse.go, ReadingMode is a string type with constants - dateProg := bible.NewDateProgression(bibleData) + // Create date progression calculator with reading mode from config + dateProg := bible.NewDateProgressionWithReadingMode(bibleData, config.DateProgression.VersesPerDay, bible.ReadingMode(config.ReadingMode)) // Get today's bookmark bookmark, err := dateProg.GetPositionForDate(time.Now())

@@ -82,7 +95,7 @@ fmt.Fprintf(os.Stderr, "Error calculating today's reading position: %v\n", err)

os.Exit(1) } - // Determine output mode: plain, formatted, or TUI + // Determine output mode: plain, formatted, or TUI // Plain mode forces no colours, formatted respects config usePlain := args.Plain useFormatted := args.Formatted

@@ -122,4 +135,5 @@ if _, err := program.Run(); err != nil {

fmt.Fprintf(os.Stderr, "Error running TUI: %v\n", err) os.Exit(1) } -}+} +
M internal/formatter.gointernal/formatter.go

@@ -121,14 +121,14 @@ for i, verse := range verses {

// Check for pilcrow to handle paragraph breaks text := strings.TrimSpace(verse.Text) hasPilcrow := strings.HasPrefix(text, "¶ ") || strings.HasPrefix(text, "¶") - + // Remove pilcrow markers if present if strings.HasPrefix(text, "¶ ") { text = text[2:] } else if strings.HasPrefix(text, "¶") { text = text[1:] } - + // Handle paragraph breaks (blank line before verse with pilcrow) if f.paragraphs && hasPilcrow && i > 0 { // Add blank line before this verse (paragraph break)

@@ -144,14 +144,14 @@ sb.WriteString("\n\n")

} } } - + // Handle numbered output if f.numbered { if i > 0 && !(f.paragraphs && hasPilcrow) { // Don't add newline if we already added one for paragraph sb.WriteString("\n") } - sb.WriteString(fmt.Sprintf("%d. %s", verse.VerseNum, text)) + fmt.Fprintf(&sb, "%d. %s", verse.VerseNum, text) } else { // Regular mode - join with spaces // Don't add space if we just added paragraph break

@@ -172,34 +172,34 @@ return "Error: No text matched"

} var resultLines []string - + for i, verse := range verses { // Process verse text text := strings.TrimSpace(verse.Text) hasPilcrow := strings.HasPrefix(text, "¶ ") || strings.HasPrefix(text, "¶") - + // Remove pilcrow markers if present if strings.HasPrefix(text, "¶ ") { text = text[2:] } else if strings.HasPrefix(text, "¶") { text = text[1:] } - + // Handle paragraph breaks (blank line before verse with pilcrow) if f.paragraphs && hasPilcrow && i > 0 { // Add blank line before this verse (paragraph break) resultLines = append(resultLines, "") } - + if f.numbered { // For numbered mode: "1. text" // Estimate number takes about 4 characters (for verse numbers up to 3 digits + ". ") const numberWidthEstimate = 4 - remainingWidth := max(1, contentWidth - numberWidthEstimate) - + remainingWidth := max(1, contentWidth-numberWidthEstimate) + numberPart := numberStyle.Render(fmt.Sprintf("%d. ", verse.VerseNum)) textPart := style.Width(remainingWidth).Render(text) - resultLines = append(resultLines, numberPart + textPart) + resultLines = append(resultLines, numberPart+textPart) } else { // For non-numbered mode, we'll handle text accumulation separately // Store plain text for now, will join and render later

@@ -212,16 +212,16 @@ resultLines[len(resultLines)-1] = resultLines[len(resultLines)-1] + " " + text

} } } - + // Apply styling to non-numbered lines if !f.numbered { for i, line := range resultLines { - if line != "" { // Keep empty lines (paragraph breaks) as is + if line != "" { // Keep empty lines (paragraph breaks) as is resultLines[i] = style.Width(contentWidth).Render(line) } } } - + return strings.Join(resultLines, "\n") }

@@ -238,10 +238,3 @@ header := f.FormatHeader(bookmark)

content := f.ExtractAndFormat(bible, bookmark) return header + "\n" + content } -// max returns the larger of two integers -func max(a, b int) int { - if a > b { - return a - } - return b -}