add --version option

This commit is contained in:
Brendan Haines 2024-09-14 13:40:16 -06:00
parent e89b1d1c89
commit 226456670a
2 changed files with 15 additions and 3 deletions

View File

@ -0,0 +1 @@
__version__ = "v0.0.0"

View File

@ -1,5 +1,6 @@
# %% imports # %% imports
import subprocess import subprocess
import sys
from pathlib import Path from pathlib import Path
from typing import List from typing import List
@ -8,7 +9,7 @@ import gotify
import numpy as np import numpy as np
import toml import toml
__version__ = "v0.0.0" from goat_monitor import __version__
# %% commands # %% commands
@ -26,9 +27,19 @@ __version__ = "v0.0.0"
type=int, type=int,
help="Number of times to try re-running failed command. -1 to retry indefinitely until success", help="Number of times to try re-running failed command. -1 to retry indefinitely until success",
) )
def wrap(command: List[str], config: Path, retries: int): @click.option(
"--version",
is_flag=True,
default=False,
help="Print version and exit",
)
def wrap(command: List[str], config: Path, retries: int, version):
"""Wrap an arbitrary command with gotify notifications""" """Wrap an arbitrary command with gotify notifications"""
if version:
print(version)
sys.exit(0)
# read settings first # read settings first
with open(config, "r") as f: with open(config, "r") as f:
settings = toml.load(f) settings = toml.load(f)
@ -85,7 +96,7 @@ def wrap(command: List[str], config: Path, retries: int):
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)
return result.returncode sys.exit(result.returncode)
# %% main # %% main