From ca78aa9e22965ee6fb4e4156169a4b92bcb8f9b3 Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Sun, 19 May 2024 06:09:50 +0200 Subject: [PATCH] cli: allow relative volume adjustment using {+,-}{,%} --- grzegorz_clients/cli.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/grzegorz_clients/cli.py b/grzegorz_clients/cli.py index 10b8602..7adb11e 100644 --- a/grzegorz_clients/cli.py +++ b/grzegorz_clients/cli.py @@ -160,10 +160,19 @@ def status( @cli.command(help="Set the playback volume") def set_volume( - volume: int, + volume: str, api_base: str = DEFAULT_API_BASE, ): api.set_endpoint(api_base) + + volume = volume.removesuffix("%") + + if volume.startswith("+") or volume.startswith("-"): + current_volume = api.get_volume() + new_volume = max(0, min(100, current_volume + int(volume))) + else: + new_volume = int(volume) + rich.print(api.set_volume(volume), file=sys.stderr)