From 226456670a2ee7b56a590dbb866ac2878addada0 Mon Sep 17 00:00:00 2001 From: Brendan Haines Date: Sat, 14 Sep 2024 13:40:16 -0600 Subject: [PATCH] add --version option --- goat_monitor/__init__.py | 1 + goat_monitor/goat_monitor.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/goat_monitor/__init__.py b/goat_monitor/__init__.py index e69de29..3d2e4df 100644 --- a/goat_monitor/__init__.py +++ b/goat_monitor/__init__.py @@ -0,0 +1 @@ +__version__ = "v0.0.0" diff --git a/goat_monitor/goat_monitor.py b/goat_monitor/goat_monitor.py index 2e07f5d..12388ca 100644 --- a/goat_monitor/goat_monitor.py +++ b/goat_monitor/goat_monitor.py @@ -1,5 +1,6 @@ # %% imports import subprocess +import sys from pathlib import Path from typing import List @@ -8,7 +9,7 @@ import gotify import numpy as np import toml -__version__ = "v0.0.0" +from goat_monitor import __version__ # %% commands @@ -26,9 +27,19 @@ __version__ = "v0.0.0" type=int, 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""" + if version: + print(version) + sys.exit(0) + # read settings first with open(config, "r") as 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: gotify_connection.create_message(message=message, title=title) - return result.returncode + sys.exit(result.returncode) # %% main