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.
This commit is contained in:
5 files changed
+60
-3
No files matched your search
@@ -8,7 +8,7 @@ They capture what was done, decisions & rationale, gotchas & fixes, and next ste
|
|||||||
<!-- write-log: session-log-index -->
|
<!-- write-log: session-log-index -->
|
||||||
| Date | Type | File | Summary |
|
| 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-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-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** |
|
| 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** |
|
||||||
|
|||||||
@@ -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/),
|
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).
|
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
|
## [1.1.0] - 2026-06-04
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -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*
|
||||||
@@ -192,7 +192,8 @@ def run(
|
|||||||
return 130
|
return 130
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main() -> None:
|
||||||
|
"""CLI entry point — parse args and run the download pipeline."""
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Download audiobooks from Libro.fm")
|
parser = argparse.ArgumentParser(description="Download audiobooks from Libro.fm")
|
||||||
@@ -225,3 +226,7 @@ if __name__ == "__main__":
|
|||||||
limit=args.limit,
|
limit=args.limit,
|
||||||
workers=args.workers,
|
workers=args.workers,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
+1
-1
@@ -22,7 +22,7 @@ dev = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
librofm-downloader = "librofm_downloader.cli:run"
|
librofm-downloader = "librofm_downloader.cli:main"
|
||||||
|
|
||||||
[tool.setuptools.packages.find]
|
[tool.setuptools.packages.find]
|
||||||
include = ["librofm_downloader*"]
|
include = ["librofm_downloader*"]
|
||||||
|
|||||||
Reference in new issue
Block a user