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,13 +52,14 @@ def wrap(command: List[str], config: Path, retries: int, version):
settings = toml.load(f) settings = toml.load(f)
# gotify configuration # gotify configuration
url = settings["server"] if not dry_run:
app_token = settings["app_token"] url = settings["server"]
with gotify.Gotify(base_url=url, app_token=app_token) as gotify_connection: app_token = settings["app_token"]
# this is just to test configuration. with gotify.Gotify(base_url=url, app_token=app_token) as gotify_connection:
# I don't know how long a gotify connection will stay up so rather than thinking about it # this is just to test configuration.
# I'm just creating a new one whenever I need to send a message # I don't know how long a gotify connection will stay up so rather than thinking about it
pass # I'm just creating a new one whenever I need to send a message
pass
if retries == -1: if retries == -1:
retries = np.inf retries = np.inf
@ -95,8 +102,9 @@ def wrap(command: List[str], config: Path, retries: int, version):
+ "\n".join(lines) + "\n".join(lines)
) )
with gotify.Gotify(base_url=url, app_token=app_token) as gotify_connection: if not dry_run:
gotify_connection.create_message(message=message, title=title) with gotify.Gotify(base_url=url, app_token=app_token) as gotify_connection:
gotify_connection.create_message(message=message, title=title)
if not result.returncode: if not result.returncode:
# only retry on failure # only retry on failure