From db592d643dde0af169b40970640f2f14ae9cd7c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20Schr=C3=B6der?=
 <fschroeder@techfak.uni-bielefeld.de>
Date: Tue, 30 Jan 2024 11:37:27 +0100
Subject: [PATCH] Refactor argument parser in Overcooked Simulator

The argument parser and related function calls have been moved from the `__main__` function in the Overcooked Simulator to the `main` function. This change streamlines the function calls and improves code readability and management. Furthermore, it ensures that essential configurations are in place before the game server and GUI are initiated.
---
 overcooked_simulator/__main__.py | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/overcooked_simulator/__main__.py b/overcooked_simulator/__main__.py
index 7b055ade..436201f2 100644
--- a/overcooked_simulator/__main__.py
+++ b/overcooked_simulator/__main__.py
@@ -23,6 +23,16 @@ def start_pygame_gui(cli_args):
 
 def main(cli_args=None):
     if cli_args is None:
+        parser = argparse.ArgumentParser(
+            prog="Overcooked Simulator",
+            description="Game Engine Server + PyGameGUI: Starts overcooked game engine server and a PyGame 2D Visualization window in two processes.",
+            epilog="For further information, see https://scs.pages.ub.uni-bielefeld.de/cocosy/overcooked-simulator/overcooked_simulator.html",
+        )
+
+        url_and_port_arguments(parser)
+        disable_websocket_logging_arguments(parser)
+        add_list_of_manager_ids_arguments(parser)
+
         cli_args = parser.parse_args()
     game_server = None
     pygame_gui = None
@@ -40,7 +50,7 @@ def main(cli_args=None):
         print("Received Keyboard interrupt")
     finally:
         if game_server is not None and game_server.is_alive():
-            print("Terminate game server")
+            print("Terminate gparserame server")
             game_server.terminate()
         if pygame_gui is not None and pygame_gui.is_alive():
             print("Terminate pygame gui")
@@ -49,15 +59,4 @@ def main(cli_args=None):
 
 
 if __name__ == "__main__":
-    parser = argparse.ArgumentParser(
-        prog="Overcooked Simulator",
-        description="Game Engine Server + PyGameGUI: Starts overcooked game engine server and a PyGame 2D Visualization window in two processes.",
-        epilog="For further information, see https://scs.pages.ub.uni-bielefeld.de/cocosy/overcooked-simulator/overcooked_simulator.html",
-    )
-
-    url_and_port_arguments(parser)
-    disable_websocket_logging_arguments(parser)
-    add_list_of_manager_ids_arguments(parser)
-
-    args = parser.parse_args()
-    main(args)
+    main()
-- 
GitLab