diff options
author | Botond Hende <nettingman@gmail.com> | 2024-11-24 23:53:13 +0100 |
---|---|---|
committer | Botond Hende <nettingman@gmail.com> | 2024-11-24 23:53:13 +0100 |
commit | 965c0e3401a4743c4f5e91e2368fd04b0b24aa02 (patch) | |
tree | d9428a6f15a6b480d079f53bbc802efca13eafca /modules/config.py | |
parent | a54f9cbed78ce3df4252c209553f4f318bc2b81e (diff) |
input_handler can be specified from config
Diffstat (limited to 'modules/config.py')
-rw-r--r-- | modules/config.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/modules/config.py b/modules/config.py index 609e4d1..83243a0 100644 --- a/modules/config.py +++ b/modules/config.py @@ -1,10 +1,18 @@ +import sys + import __main__ import os.path import yaml class Config: + INPUT_PW = "pw-record" + INPUT_STDIN = "stdin" + INPUT_MODES = [INPUT_PW, INPUT_STDIN] + def __init__(self): + self.input_mode = "" + self.intents_dir = "" self.applications_dir = "" @@ -16,6 +24,10 @@ class Config: if not self.intents_dir.startswith("/"): self.intents_dir = os.path.join(os.path.dirname(__main__.__file__), self.intents_dir) + def validate(self): + if self.input_mode not in self.INPUT_MODES: + sys.exit(f"Invalid input_mode '{self.input_mode}', valid options: {", ".join(self.INPUT_MODES)}") + def load_config(): config = Config() with open(os.path.join(os.path.dirname(__main__.__file__), "config.yaml")) as stream: @@ -26,4 +38,5 @@ def load_config(): with open(user_config) as stream: config.update(**yaml.safe_load(stream)) + config.validate() return config
\ No newline at end of file |