From b4702c1a72a4f8b7108ab5bad249c7e7f1d573de Mon Sep 17 00:00:00 2001 From: Max P Date: Mon, 19 Aug 2024 19:02:40 +0200 Subject: [PATCH] Update config path resolution logic - Modify `resolve_config_path` to check for `.json` files. - First check in the current directory. - Then check in `.ait` directory in the user's home directory. - Return filename even if non-existent for later failure handling. --- ait.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ait.py b/ait.py index b65feb6..dfe772a 100644 --- a/ait.py +++ b/ait.py @@ -22,7 +22,8 @@ def load_config(config_path): def resolve_config_path(config_input): """ Resolves the configuration file path. If a single word is provided, - it looks for a file named 'ait.WORD.config' in the current directory. + it looks for a file named 'ait.WORD.config.json' in the current directory first, + then in a '.ait' directory in the user's home directory. Parameters: - config_input (str): The input provided via the command-line argument. @@ -30,9 +31,24 @@ def resolve_config_path(config_input): Returns: - str: The resolved path to the configuration file. """ + # If it's a keyword, construct the potential filenames if not config_input.endswith(".json"): - config_input = f"ait.{config_input}.config.json" - return config_input + config_filename = f"ait.{config_input}.config.json" + else: + config_filename = config_input + + # Check in the current directory + if os.path.exists(config_filename): + return config_filename + + # Check in the user's home directory under .ait/ + home_directory = os.path.expanduser("~") + user_config_path = os.path.join(home_directory, ".ait", config_filename) + if os.path.exists(user_config_path): + return user_config_path + + # If nothing found, return the filename (it will fail later if non-existent) + return config_filename def run_git_commands(diff_expression, log_expression): """