From 136b1e491159bc0a0854dd0d23527287d2b67b60 Mon Sep 17 00:00:00 2001 From: Cole <95713039+chughes741@users.noreply.github.com> Date: Fri, 4 Aug 2023 21:12:58 -0400 Subject: [PATCH] Added prompt and overwrite to setup/__main__.py (#24) --- openct/setup/__main__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/openct/setup/__main__.py b/openct/setup/__main__.py index 59acb2a..0e2d199 100644 --- a/openct/setup/__main__.py +++ b/openct/setup/__main__.py @@ -1,7 +1,18 @@ """Config file generator.""" +import os + import yaml +CONFIG_FILE = "config.yml" + +if os.path.exists(CONFIG_FILE): + user_input = input( + f"The config file '{CONFIG_FILE}' already exists. Do you want to overwrite it? (yes/no): " + ).lower() + if user_input != "yes" and user_input != "y": + print("Config file not overwritten. Exiting.") + exit() mt_backup_config = { "identity": { @@ -21,5 +32,5 @@ }, } -with open(file="config.yml", mode="a", encoding="utf-8") as file: +with open(file=CONFIG_FILE, mode="w", encoding="utf-8") as file: yaml.dump(mt_backup_config, file, default_flow_style=False)