From 293cc6c68406c5ab24a60e068defbf84a6ec4e98 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 24 May 2024 08:41:23 -0700 Subject: [PATCH] aider: Update main function to list and filter Python files if no filenames are provided. # Aider chat conversation: USER: if no files are provided on cmd line, do git ls-files and filter to python files ASSISTANT: To implement the requested change, we need to modify the `main` function to use `git ls-files` to list all files in the repository and filter them to include only Python files if no filenames are provided on the command line. Here is the *SEARCH/REPLACE* block: ```python scripts/blame.py ```python <<<<<<< SEARCH if len(sys.argv) < 2: print(f"Usage: {sys.argv[0]} ...") sys.exit(1) ======= if len(sys.argv) < 2: result = subprocess.run( ["git", "ls-files"], capture_output=True, text=True, check=True ) fnames = [fname for fname in result.stdout.splitlines() if fname.endswith('.py')] if not fnames: print("No Python files found in the repository.") sys.exit(1) else: fnames = sys.argv[1:] >>>>>>> REPLACE ``` This change ensures that if no filenames are provided on the command line, the script will list all files in the repository, filter them to include only Python files, and then process those files. --- scripts/blame.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/blame.py b/scripts/blame.py index aeba6ddef..18cdc9c1a 100755 --- a/scripts/blame.py +++ b/scripts/blame.py @@ -71,8 +71,18 @@ def process(fnames): def main(): if len(sys.argv) < 2: - print(f"Usage: {sys.argv[0]} ...") - sys.exit(1) + result = subprocess.run( + ["git", "ls-files"], + capture_output=True, + text=True, + check=True + ) + fnames = [fname for fname in result.stdout.splitlines() if fname.endswith('.py')] + if not fnames: + print("No Python files found in the repository.") + sys.exit(1) + else: + fnames = sys.argv[1:] process(sys.argv[1:])