Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 9 additions & 3 deletions lib/commands/cmd_list.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Number books by sorted index, not alphabetical_order

Using item.alphabetical_order as the displayed numeric column makes bible list books --alphabetical output ambiguous, because those values are not unique in the data model (for example, I Samuel and Mark both use 28, and several books share 25 in lib/models/models.ml). This change introduces repeated/missing numbers in the left column, so users can no longer treat it as a position indicator; computing the number from the book's index in the sorted list would keep the column stable and meaningful.

Useful? React with 👍 / 👎.

| 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
Expand Down
12 changes: 3 additions & 9 deletions lib/commands/cmd_read.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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
Expand All @@ -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 ->
Expand Down
Loading