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