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]} <filename> ...")
        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.
This commit is contained in:
Paul Gauthier 2024-05-24 08:41:23 -07:00
parent 8c09670a5b
commit 293cc6c684

View file

@ -71,8 +71,18 @@ def process(fnames):
def main():
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <filename> ...")
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:])