From 921546881e0e8681b2ccca283c8be018bf1bb0e2 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 12:54:09 -0700 Subject: [PATCH] aider: Added error message when no files matched in cmd_add and cmd_drop. # Context: USER: in cmd_add and cmd_drop, print an error if no files matched ASSISTANT: To print an error message when no files are matched in `cmd_add` and `cmd_drop`, you can add a check for the length of `matched_files` and print an error message if it's zero. Here are the changes: ```python aider/coder.py <<<<<<< ORIGINAL def cmd_add(self, args): "Add matching files to the chat" files = self.get_active_files() for word in args.split(): matched_files = [file for file in files if word in file] ======= def cmd_add(self, args): "Add matching files to the chat" files = self.get_active_files() for word in args.split(): matched_files = [file for file in files if word in file] if not matched_files: self.console.print(f"[red]No files matched '{word}'") >>>>>>> UPDATED aider/coder.py <<<<<<< ORIGINAL def cmd_drop(self, args): "Remove matching files from the chat" for word in args.split(): matched_files = [file for file in self.fnames if word in os.path.relpath(file, self.root)] ======= def cmd_drop(self, args): "Remove matching files from the chat" for word in args.split(): matched_files = [file for file in self.fnames if word in os.path.relpath(file, self.root)] if not matched_files: self.console.print(f"[red]No files matched '{word}'") >>>>>>> UPDATED ``` --- aider/coder.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aider/coder.py b/aider/coder.py index ad88f2b1e..d18a242ef 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -543,6 +543,8 @@ class Coder: files = self.get_active_files() for word in args.split(): matched_files = [file for file in files if word in file] + if not matched_files: + self.console.print(f"[red]No files matched '{word}'") for matched_file in matched_files: abs_file_path = os.path.abspath(os.path.join(self.root, matched_file)) if abs_file_path not in self.fnames: @@ -556,6 +558,8 @@ class Coder: for word in args.split(): matched_files = [file for file in self.fnames if word in os.path.relpath(file, self.root)] + if not matched_files: + self.console.print(f"[red]No files matched '{word}'") for matched_file in matched_files: relative_fname = os.path.relpath(matched_file, self.root) self.fnames.remove(matched_file)