feat(sync_run): wire --select into download pipeline

Replace select_mode stub with real selection pipeline:
- TTY guard: non-interactive terminals get fatal_error exit
- Convert filtered dicts to Books via from_library_row()
- Call select_books(), pass selected Books to orchestrator
- Orchestrator accepts pre-converted Book objects (isinstance check)
- --limit bypassed when --select is active, with verbose note
- Remove "[not implemented]" from --select help text

Closes #48
This commit is contained in:
AlexKucera committed 2026-06-06 12:13:56 +02:00
1 parent 0d555e4628
commit fa1543e3d7
9 files changed
+306 -22

No files matched your search

+1 -1
View File
@@ -50,7 +50,7 @@ def main() -> None:
parser.add_argument("-w", "--workers", type=int, default=0, metavar="N", help="Parallel workers (0=config)")
parser.add_argument("--rename-chapters", action="store_true", default=False,
help="Rename chapter files (default: use config)")
parser.add_argument("--select", action="store_true", default=False, help="Interactive selection [not implemented]")
parser.add_argument("--select", action="store_true", default=False, help="Interactive book selection")
args = parser.parse_args()
exit_code = run(
config_path=args.config, secrets_path=args.secrets, history_path=args.history,
+9 -4
View File
@@ -113,10 +113,15 @@ def download_all_books(
if not raw_books:
return OrchestratorResult()
# Convert raw dicts to Book objects, preserving order and index
books_with_index: list[tuple[int, Book]] = [
(i, from_library_row(raw)) for i, raw in enumerate(raw_books)
]
# Convert raw dicts to Book objects, preserving order and index.
# Accept pre-converted Book objects directly to avoid double-conversion
# when select mode has already called from_library_row().
books_with_index: list[tuple[int, Book]] = []
for i, raw in enumerate(raw_books):
if isinstance(raw, Book):
books_with_index.append((i, raw))
else:
books_with_index.append((i, from_library_row(raw)))
downloaded_count = 0
skipped_count = 0
+22 -5
View File
@@ -11,6 +11,7 @@ calls sync_run() and translates SyncRunResult → exit code.
from __future__ import annotations
import os
import sys
import threading
from collections.abc import Callable
from dataclasses import dataclass, field
@@ -124,7 +125,7 @@ def sync_run(
verbose: Print extra detail (URLs, paths, API responses).
limit: Maximum number of books to download (0 = no limit).
workers: Parallel download worker count (0 = use config value).
select_mode: Interactive book selection (ADR #6, not yet implemented).
select_mode: Interactive book selection (ADR #6).
Returns:
SyncRunResult with counts and per-book details.
@@ -202,7 +203,7 @@ def sync_run(
if history is None:
history = DownloadHistory(history_path)
new_books = [b for b in books if not history.is_downloaded(b.get("isbn", ""))]
if limit:
if limit and not select_mode:
new_books = new_books[:limit]
if verbose:
@@ -213,10 +214,26 @@ def sync_run(
console.print("[green]All caught up! No new books to download.[/green]")
return SyncRunResult()
# 5. Select mode branch point (ADR #6 — stub)
# 5. Select mode pipeline (ADR #6)
if select_mode:
console.print("[red]--select is not yet implemented.[/red]")
return SyncRunResult()
if not sys.stdout.isatty():
console.print("[red]--select requires an interactive terminal.[/red]")
return SyncRunResult(fatal_error="--select requires an interactive terminal")
from librofm_downloader.book import from_library_row
from librofm_downloader.selector import select_books
selectable_books = [from_library_row(b) for b in new_books]
selected = select_books(selectable_books)
if not selected:
return SyncRunResult()
if limit and verbose:
console.print("[dim]Selection mode active -- --limit superseded by manual selection.[/dim]")
# Replace new_books with selected Books; orchestrator will
# receive pre-converted Book objects.
new_books = selected # type: ignore[assignment]
# 6. Download loop with TTY-aware reporting
if reporter is None: