adding flag for user confirmation

- Modified the code to ask for changes to be applied. If they say yes then it will make the change or else code will stop running.
pull/16/head
Prayag Shah 2023-04-14 00:10:36 -03:00
rodzic 1b9649ed7a
commit e65a4d080a
1 zmienionych plików z 36 dodań i 13 usunięć

Wyświetl plik

@ -94,6 +94,20 @@ def apply_changes(file_path, changes_json):
elif operation == "InsertAfter":
file_lines.insert(line, content + "\n")
# Ask for user confirmation before writing changes
print("\nChanges to be made:")
diff = difflib.unified_diff(original_file_lines, file_lines, lineterm="")
for line in diff:
if line.startswith("+"):
cprint(line, "green", end="")
elif line.startswith("-"):
cprint(line, "red", end="")
else:
print(line, end="")
confirmation = input("Do you want to apply these changes? (y/n): ")
if confirmation.lower() == "y":
with open(file_path, "w") as f:
f.writelines(file_lines)
@ -104,7 +118,8 @@ def apply_changes(file_path, changes_json):
# Show the diff
print("\nChanges:")
diff = difflib.unified_diff(original_file_lines, file_lines, lineterm="")
diff = difflib.unified_diff(
original_file_lines, file_lines, lineterm="")
for line in diff:
if line.startswith("+"):
cprint(line, "green", end="")
@ -113,6 +128,14 @@ def apply_changes(file_path, changes_json):
else:
print(line, end="")
print("Changes applied.")
# sys.exit(0)
# Ending the code once they hit n or N
else:
print("Changes not applied")
sys.exit(0)
def main(script_name, *script_args, revert=False, model="gpt-4"):
if revert: