From e5b27355b7852d1c4d69668095e6ba58250d3108 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 2 Oct 2024 09:16:08 -0700 Subject: [PATCH] feat: use glob for flexible file matching in cmd_read_only --- aider/commands.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 07afd912e..42ba88f2a 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -3,6 +3,7 @@ import re import subprocess import sys import tempfile +import glob from collections import OrderedDict from pathlib import Path @@ -1137,21 +1138,20 @@ class Commands: return filenames = parse_quoted_filenames(args) - for word in filenames: - # Expand the home directory if the path starts with "~" - expanded_path = os.path.expanduser(word) - abs_path = self.coder.abs_root_path(expanded_path) - - if not os.path.exists(abs_path): - self.io.tool_error(f"Path not found: {abs_path}") + for pattern in filenames: + expanded_paths = glob.glob(pattern, recursive=True) + if not expanded_paths: + self.io.tool_error(f"No matches found for: {pattern}") continue - if os.path.isfile(abs_path): - self._add_read_only_file(abs_path, word) - elif os.path.isdir(abs_path): - self._add_read_only_directory(abs_path, word) - else: - self.io.tool_error(f"Not a file or directory: {abs_path}") + for path in expanded_paths: + abs_path = self.coder.abs_root_path(path) + if os.path.isfile(abs_path): + self._add_read_only_file(abs_path, path) + elif os.path.isdir(abs_path): + self._add_read_only_directory(abs_path, path) + else: + self.io.tool_error(f"Not a file or directory: {abs_path}") def _add_read_only_file(self, abs_path, original_name): if abs_path in self.coder.abs_read_only_fnames: