From 3411a5a34d8f3cd784e8d01606cae9f572dda3f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6tz?= Date: Sat, 28 Feb 2026 15:42:49 -0500 Subject: [PATCH] cli: exit early for --help/--version without starting app The CLI previously always started full app initialization (config load, listener setup, receiver construction, and debug output) even when invoked with `-h`, `--help`, `-v`, or `--version`. That made basic introspection noisy and buried the requested output in startup logs. Add early argument checks in `main()` so help/version requests are handled immediately and the process exits without starting the app. Introduce a small `print_help()` helper for consistent usage output. This improves terminal UX and makes debugging/invocation checks much clearer by keeping `-h` and `-v` output focused and predictable. --- src/mpd_now_playable/cli.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/mpd_now_playable/cli.py b/src/mpd_now_playable/cli.py index 34153c2..d4f9caa 100644 --- a/src/mpd_now_playable/cli.py +++ b/src/mpd_now_playable/cli.py @@ -1,4 +1,5 @@ import asyncio +import sys from collections.abc import Iterable from rich import print @@ -22,7 +23,23 @@ async def listen( await listener.loop(receivers) +def print_help() -> None: + print("Usage: mpd-now-playable [OPTIONS]") + print("") + print("Options:") + print(" -h, --help Show this help message and exit.") + print(" -v, --version Show version and exit.") + + def main() -> None: + args = set(sys.argv[1:]) + if "-h" in args or "--help" in args: + print_help() + return + if "-v" in args or "--version" in args: + print(f"mpd-now-playable v{__version__}") + return + print(f"mpd-now-playable v{__version__}") config = loadConfig() print(config)