Add --show-diffs parameter and only print diffs if it is set to True.

# Context:
USER: add a --show-diffs parameter  which defaults to false. allow an env var to override the default. pass this to Coder.__init__() and use it to set a self.show_diffs. only self.console.print(Text(diffs)) if it is true.
ASSISTANT: To add a `--show-diffs` parameter with a default value of `False` and allow an environment variable to override the default, we will make changes to `aider/main.py`. We will also pass this value to `Coder.__init__()` and use it to set `self.show_diffs`. Finally, we will only print the diffs if `self.show_diffs` is `True`.

Here are the changes:

```python
aider/main.py
<<<<<<< ORIGINAL
        default=bool(int(os.environ.get(f"{env_prefix}COMMIT_DIRTY", 0))),
    )
    args = parser.parse_args()
=======
        default=bool(int(os.environ.get(f"{env_prefix}COMMIT_DIRTY", 0))),
    )
    parser.add_argument(
        "--show-diffs",
        action="store_true",
        help=f"Show diffs when committing changes (default: False, ${env_prefix}SHOW_DIFFS)",
        default=bool(int(os.environ.get(f"{env_prefix}SHOW_DIFFS", 0))),
    )
    args = parser.parse_args()
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(args.model, fnames, pretty, args.history_file)
=======
    coder = Coder(args.model, fnames, pretty, args.history_file, args.show_diffs)
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
    def __init__(self, main_model, files, pretty, history_file):
=======
    def __init__(self, main_model, files, pretty, history_file, show_diffs):
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
        self.pretty = pretty
=======
        self.pretty = pretty
        self.show_diffs = show_diffs
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
        self.console.print(Text(diffs))
=======
        if self.show_diffs:
            self.console.print(Text(diffs))
>>>>>>> UPDATED
```

These changes will add the `--show-diffs` parameter and only print the diffs if the parameter is set to `True`.
This commit is contained in:
Paul Gauthier 2023-05-09 13:04:43 -07:00
parent 0782e50f6d
commit 540c0b10b9
2 changed files with 11 additions and 6 deletions

View file

@ -31,7 +31,7 @@ class Coder:
last_modified = 0
repo = None
def __init__(self, main_model, files, pretty, history_file):
def __init__(self, main_model, files, pretty, history_file, show_diffs):
self.history_file = history_file
if pretty:
@ -62,7 +62,7 @@ class Coder:
)
self.pretty = pretty
self.show_diffs = show_diffs
def set_repo(self):
repo_paths = []
for fname in self.fnames:
@ -372,8 +372,8 @@ class Coder:
self.last_modified = self.get_last_modified()
return
self.console.print(Text(diffs))
if self.show_diffs:
self.console.print(Text(diffs))
diffs = "# Diffs:\n" + diffs
# for fname in dirty_fnames: