fix: Simplify cmd_read_only function

This commit is contained in:
Paul Gauthier (aider) 2024-08-22 16:51:51 -07:00
parent 9584a7f296
commit 837ed0367c

View file

@ -1037,33 +1037,25 @@ class Commands:
filenames = parse_quoted_filenames(args)
for word in filenames:
# If no files matched, try to use the word as a direct file path
if os.path.exists(word) and os.path.isfile(word):
matched_files = [word]
else:
self.io.tool_error(f"No files matched '{word}'.")
abs_path = self.coder.abs_root_path(word)
if not os.path.exists(abs_path):
self.io.tool_error(f"File not found: {abs_path}")
continue
for matched_file in matched_files:
abs_path = self.coder.abs_root_path(matched_file)
if not os.path.exists(abs_path):
self.io.tool_error(f"File not found: {abs_path}")
continue
if not os.path.isfile(abs_path):
self.io.tool_error(f"Not a file: {abs_path}")
continue
if not os.path.isfile(abs_path):
self.io.tool_error(f"Not a file: {abs_path}")
continue
if abs_path in self.coder.abs_fnames:
self.io.tool_error(f"{word} is already in the chat as an editable file")
continue
if abs_path in self.coder.abs_fnames:
self.io.tool_error(f"{matched_file} is already in the chat as an editable file")
continue
if abs_path in self.coder.abs_read_only_fnames:
self.io.tool_error(f"{word} is already in the chat as a read-only file")
continue
if abs_path in self.coder.abs_read_only_fnames:
self.io.tool_error(f"{matched_file} is already in the chat as a read-only file")
continue
self.coder.abs_read_only_fnames.add(abs_path)
self.io.tool_output(f"Added {matched_file} to read-only files.")
self.coder.abs_read_only_fnames.add(abs_path)
self.io.tool_output(f"Added {word} to read-only files.")
def cmd_map(self, args):
"Print out the current repository map"