From 722413a45be1e27f48c78825e79b7002c0b48655 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Thu, 4 Jun 2026 11:19:10 +0200 Subject: [PATCH] fix(cli): wire verbose flag through entry point Extract argparse into main() and point console script at it. The -v/--verbose flag was dead because the entry point called run() directly, bypassing the __main__ argparse block entirely. --- AGENTS.md | 2 +- CHANGELOG.md | 7 +++ ...g-not-wired-through-cli-entry-point_log.md | 45 +++++++++++++++++++ librofm_downloader/cli.py | 7 ++- pyproject.toml | 2 +- 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 docs/devlog/20260604-fix-verbose-flag-not-wired-through-cli-entry-point_log.md diff --git a/AGENTS.md b/AGENTS.md index 197092e..c60a0b8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,7 +8,7 @@ They capture what was done, decisions & rationale, gotchas & fixes, and next ste | Date | Type | File | Summary | |------|------|------|---------| -| 2026-06-04 | issue | [20260604-issue23-wire-xdg-resolution-into-cli_log.md](docs/devlog/20260604-issue23-wire-xdg-resolution-into-cli_log.md) | **Issue #23 Complete:** Wire XDG resolution into CLI — history path XDG default, verbose resolved paths, searched-paths message. **7 new tests, 188 total** · **10/10 AC** | +| 2026-06-04 | issue | [20260604-fix-verbose-flag-not-wired-through-cli-entry-point_log.md](docs/devlog/20260604-fix-verbose-flag-not-wired-through-cli-entry-point_log.md) | **Fix:** `-v`/`--verbose` flag dead — argparse was in `__main__` guard, never reached by installed console script. Extracted `main()`, updated entry point. **247/247 tests pass** | | 2026-06-04 | issue | [20260604-issue22-xdg-config-path-resolution-with-cwd-fallback_log.md](docs/devlog/20260604-issue22-xdg-config-path-resolution-with-cwd-fallback_log.md) | **Issue #22 Complete:** XDG→CWD path resolution, `load_config(None, None)` search, missing-config notice, OS→domain error wrapping. **9 new tests, 181 total** · **8/8 AC** | | 2026-06-03 | issue | [20260603-cli-parallel-integration-and-ctrl-c-drain-issue17_log.md](docs/devlog/20260603-cli-parallel-integration-and-ctrl-c-drain-issue17_log.md) | **Issue #17 Complete:** CLI parallel integration + graceful Ctrl+C drain. Orchestrator catches KeyboardInterrupt, drains in-flight downloads (shutdown(wait=True)), double-Ctrl+C fast exit. **13 new tests, 231 total** · **10/10 AC** | | 2026-06-03 | issue | [20260603-parallel-download-orchestrator-issue16_log.md](docs/devlog/20260603-parallel-download-orchestrator-issue16_log.md) | **Issue #16 Complete:** `orchestrator.py` — `ThreadPoolExecutor` parallel download engine. Replaces sequential for-loop in cli.py. `OrchestratorResult` dataclass, stable-sort ordering, failure isolation. **20 new tests, 218 total** · **11/11 AC** | diff --git a/CHANGELOG.md b/CHANGELOG.md index 986cfd0..ce606bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed +- **cli:** Extract `main()` so argparse runs for installed console script. + `-v`/`--verbose` was dead because the entry point called `run()` + directly, bypassing the `if __name__ == "__main__"` argparse block. + ## [1.1.0] - 2026-06-04 ### Added diff --git a/docs/devlog/20260604-fix-verbose-flag-not-wired-through-cli-entry-point_log.md b/docs/devlog/20260604-fix-verbose-flag-not-wired-through-cli-entry-point_log.md new file mode 100644 index 0000000..dda4d3d --- /dev/null +++ b/docs/devlog/20260604-fix-verbose-flag-not-wired-through-cli-entry-point_log.md @@ -0,0 +1,45 @@ +# Fix: `-v` / `--verbose` flag not wired through CLI entry point + +> **Date:** 2026-06-04 +> **Type:** issue +> **Reference:** User-reported bug — `-v` flag does nothing + +## Goal + +Fix the `-v` / `--verbose` CLI flag which was accepted on the command line but never actually parsed or passed to `run()`, making verbose mode completely non-functional for installed console scripts. + +## What Was Done + +- Extracted `argparse` block out of `if __name__ == "__main__":` guard in `librofm_downloader/cli.py` into a proper `main()` function +- Updated `pyproject.toml` entry point from `librofm_downloader.cli:run` → `librofm_downloader.cli:main` +- Verified all 247 tests pass (36 CLI tests + 211 others) +- Reinstalled package (`pip install -e .`) and confirmed `librofm-downloader --help` shows `-v, --verbose` + +## Decisions & Rationale + +| Decision | Rationale | +|----------|-----------| +| Keep `run()` unchanged, add `main()` alongside it | `run()` is called directly with keyword args by 36 tests. Renaming it would break all tests for no benefit. A thin `main()` wrapper is the cleanest fix. | +| `main()` calls `sys.exit(run(...))` | Preserves the exact same exit-code behavior as the old `__main__` block. | +| `if __name__ == "__main__": main()` guard kept | Allows `python -m librofm_downloader.cli` to still work for development. | + +## Gotchas & Fixes + +| Problem | Root Cause | Fix | +|---------|------------|-----| +| `-v` flag does nothing | `pyproject.toml` pointed console script entry at `run()` directly. `run()` expects parsed keyword args, not `sys.argv`. The argparse code was inside `if __name__ == "__main__":` which only executes when running the file directly via Python, never for installed console scripts. | Extracted argparse into `main()` and pointed entry point at `main()`. | + +## Files Changed + +| File | Change Summary | +|------|---------------| +| `librofm_downloader/cli.py` | Extracted argparse from `__main__` guard into `main()` function; added `main()` as proper CLI entry point | +| `pyproject.toml` | Changed `[project.scripts]` entry point from `librofm_downloader.cli:run` to `librofm_downloader.cli:main` | + +## Open Items & Next Steps + +None + +--- + +*Log written by write-log skill* diff --git a/librofm_downloader/cli.py b/librofm_downloader/cli.py index db1a709..2b80327 100644 --- a/librofm_downloader/cli.py +++ b/librofm_downloader/cli.py @@ -192,7 +192,8 @@ def run( return 130 -if __name__ == "__main__": +def main() -> None: + """CLI entry point — parse args and run the download pipeline.""" import argparse parser = argparse.ArgumentParser(description="Download audiobooks from Libro.fm") @@ -225,3 +226,7 @@ if __name__ == "__main__": limit=args.limit, workers=args.workers, )) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 8de0144..4486ebb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ dev = [ ] [project.scripts] -librofm-downloader = "librofm_downloader.cli:run" +librofm-downloader = "librofm_downloader.cli:main" [tool.setuptools.packages.find] include = ["librofm_downloader*"]