add dry-run

This commit is contained in:
Brendan Haines 2024-09-14 17:59:49 -06:00
parent e02737abd1
commit 0e9eba4900

View File

@ -34,7 +34,13 @@ from goat_monitor._version import __version__ # type: ignore
default=False, default=False,
help="Print version and exit", help="Print version and exit",
) )
def wrap(command: List[str], config: Path, retries: int, version): @click.option(
"--dry-run",
is_flag=True,
default=False,
help="Run command without sending any notifications",
)
def wrap(command: List[str], config: Path, retries: int, version: bool, dry_run: bool):
"""Wrap an arbitrary command with gotify notifications""" """Wrap an arbitrary command with gotify notifications"""
if version: if version:
@ -46,6 +52,7 @@ def wrap(command: List[str], config: Path, retries: int, version):
settings = toml.load(f) settings = toml.load(f)
# gotify configuration # gotify configuration
if not dry_run:
url = settings["server"] url = settings["server"]
app_token = settings["app_token"] app_token = settings["app_token"]
with gotify.Gotify(base_url=url, app_token=app_token) as gotify_connection: with gotify.Gotify(base_url=url, app_token=app_token) as gotify_connection:
@ -95,6 +102,7 @@ def wrap(command: List[str], config: Path, retries: int, version):
+ "\n".join(lines) + "\n".join(lines)
) )
if not dry_run:
with gotify.Gotify(base_url=url, app_token=app_token) as gotify_connection: with gotify.Gotify(base_url=url, app_token=app_token) as gotify_connection:
gotify_connection.create_message(message=message, title=title) gotify_connection.create_message(message=message, title=title)