From 52310a902181af0cc042fb3fab8a8e12ebe965b2 Mon Sep 17 00:00:00 2001
From: Falko Habel <Falko.Habel@gmx.de>
Date: Mon, 20 May 2024 13:24:27 +0200
Subject: [PATCH] added better documentation

---
 project.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/project.py b/project.py
index 73be612..542bfe9 100644
--- a/project.py
+++ b/project.py
@@ -19,18 +19,21 @@ def main():
 
     args = parser.parse_args()
     config = read_config()
-
+    # If no config file exists and user does not go into "config mode"
     if config is None and args.config is False:
         sys.exit("No Config available. please run: 'python project.py --config' to set it up")
-
+    # add config
     elif args.config is True:
        config = configure()
        write_config(config)
+    # change ui mode
     elif args.m:
         config = handle_change_mode(args)
         write_config(config)
+    # start terminal ui
     elif config["mode"] == "terminal":
         handle_terminal(args)
+    # start customtkinter ui
     elif config["mode"] == "gui":
         # start gui
         try:
@@ -70,9 +73,13 @@ def read_config():
     with open(CONFIG_FILE, "r") as f:
         return json.load(f)
 
+
 def write_config(config: dict):
-    with open(CONFIG_FILE, "w") as config_file:
-        json.dump(config, config_file, indent=4)
+    try:
+        with open(CONFIG_FILE, "w") as config_file:
+            json.dump(config, config_file, indent=4)
+    except FileNotFoundError:
+        sys.exit(ERROR_CORRPUTED_CONFIG)
 
 def handle_change_mode(args):
     config = read_config()
@@ -88,7 +95,7 @@ def handle_change_mode(args):
 
 def handle_terminal(args):
     config = read_config()
-
+    # if a prompt exists
     if args.p:
         try:
             bot = TerminalBot(args.p, args.f, **config["ollamaConfig"])