From 8411a4bd7060a67c7eb652d49c576d22ec186b00 Mon Sep 17 00:00:00 2001 From: Adam Buchweitz Date: Mon, 23 Feb 2026 14:03:16 -0800 Subject: [PATCH] Improve list/read command behavior and cleanups --- README.md | 2 +- lib/commands/cmd_list.ml | 12 +++++++++--- lib/commands/cmd_read.ml | 12 +++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e0a28fb..6022a11 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # bible-cli -A command-line interface for accessing Bible content from the bible.helloao.org API. Supports listing available translations and books, reading specific vreses, chapters, or entire books, and exporting content to files. +A command-line interface for accessing Bible content from the bible.helloao.org API. Supports listing available translations and books, reading specific verses, chapters, or entire books, and exporting content to files. ## Usage diff --git a/lib/commands/cmd_list.ml b/lib/commands/cmd_list.ml index f07447e..9b29333 100644 --- a/lib/commands/cmd_list.ml +++ b/lib/commands/cmd_list.ml @@ -27,17 +27,23 @@ let list_books sort_order = | Alphabetical -> sort_by_alphabetical_order | Chronological -> sort_by_chronological_order in + let displayed_position = match sort_order with + | Traditional -> (fun item -> item.traditional_order) + | Alphabetical -> (fun item -> item.alphabetical_order) + | Chronological -> (fun item -> item.chronological_order) + in bible_books |> sort - |> List.fold_left (fun acc item -> sprintf "%s\n%02d | %s" acc item.traditional_order item.name) "" + |> List.fold_left (fun acc item -> sprintf "%s\n%02d | %s" acc (displayed_position item) item.name) "" |> print_endline type list_type = Translations | Books let list target ~sort_order () = - Printf.printf "The books of the Bible, sorted %sly:\n" (sort_str sort_order); match target with - | Books -> list_books sort_order + | Books -> + Printf.printf "The books of the Bible, sorted %sly:\n" (sort_str sort_order); + list_books sort_order | Translations -> list_translations () open Cmdliner diff --git a/lib/commands/cmd_read.ml b/lib/commands/cmd_read.ml index 4c280e6..a6d9c5f 100644 --- a/lib/commands/cmd_read.ml +++ b/lib/commands/cmd_read.ml @@ -35,9 +35,7 @@ let build_verse translation book chap verse output = let build_chapter translation book chap output options chapters_mode = let response = Api.fetch_chapter translation book chap in - let content = Some (format_chapter_content response.chapter.content options) - |> Option.fold ~none: (sprintf "Unable to find %s %d" book chap) ~some: Fun.id - in + let content = format_chapter_content response.chapter.content options in match output with | None -> print_endline content | Some output_dir -> @@ -81,9 +79,7 @@ let read_book translation book output options chapters_mode = let content = format_chapter_content chapter.content options in if options.showChapters then sprintf "\n\n\n# ~~~ Chapter %d ~~~\n\n%s" (i+1) content else content ) built_book |> String.concat "" - |> Str.global_replace (Str.regexp "\n\n\n") "\n\n" - |> Str.global_replace (Str.regexp "\n\n\n") "\n\n" - |> Str.global_replace (Str.regexp "\n\n\n") "\n\n" + |> Str.global_replace (Str.regexp "\n\n\n+") "\n\n" |> print_endline | Some output_dir -> if chapters_mode then @@ -97,9 +93,7 @@ let read_bible translation output options chapters_mode = let char = input_char stdin in let _ = input_char stdin in if (Char.lowercase_ascii char) = 'y' then - let book_list = Api.fetch_books translation - |> List.rev - |> List.take 2 in + let book_list = Api.fetch_books translation |> List.rev in let book_lists = List.map (fun book -> book.commonName, build_book translation book.id) book_list in match output with | None ->