From 0c0c9597bca10621923ca97a666e16ff50f5b026 Mon Sep 17 00:00:00 2001 From: Dev Mukherjee Date: Tue, 19 Dec 2023 09:57:40 +1100 Subject: [PATCH] refactor: move configuration to package root moves the environment variable configuration to the root of the package clean up various imports post asyncio workaround, see previous commit for details on how typer asyncio works REFS #18 #13 --- gallagher/cli/__init__.py | 18 +++++++++++++++++- gallagher/cli/alarms.py | 5 ----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/gallagher/cli/__init__.py b/gallagher/cli/__init__.py index 8d2245a3..97f75a11 100644 --- a/gallagher/cli/__init__.py +++ b/gallagher/cli/__init__.py @@ -1,16 +1,32 @@ """ CLI entry point +gal is the gallagher command line, which is constructed using Typer. +At the moment typer does not support async functions, so we have to +use a wrapper to make it work. See utils.py for the AsyncTyper class. +The cli should be pretty self documenting, however see docs/ for +official documentation. """ -from gallagher import __version__ +import os + +from gallagher import ( + cc, + __version__ +) from .utils import AsyncTyper from .alarms import app as alarms_app from .cardholders import app as cardholders_app +# Load the API key for the package so all entry points +# can use it to query the service +api_key = os.environ.get("GACC_API_KEY") +cc.api_key = api_key + # Main Typer app use to create the CLI app = AsyncTyper() +# Load up all sub commands app.add_typer(alarms_app, name="alarms") app.add_typer(cardholders_app, name="ch") diff --git a/gallagher/cli/alarms.py b/gallagher/cli/alarms.py index 729f1c24..bc1dc811 100644 --- a/gallagher/cli/alarms.py +++ b/gallagher/cli/alarms.py @@ -3,13 +3,8 @@ """ -import os -from gallagher import cc from .utils import AsyncTyper -api_key = os.environ.get("GACC_API_KEY") - -cc.api_key = api_key app = AsyncTyper()