aider/aider/main.py
Paul Gauthier 68c58ea394 aider: Added --ctags argument and environment variable to pass to Coder class.
# Context:
USER: add a --ctags arg and env var. pass it to Coder to set self.use_ctags
ASSISTANT: To add a `--ctags` argument and environment variable, and pass it to the `Coder` class, follow these steps:

1. Modify `aider/main.py` to add the `--ctags` argument and read the environment variable.
2. Modify the `Coder` class in `aider/coder.py` to accept the `use_ctags` parameter and set it as an instance variable.

Here are the necessary code changes:

```python
aider/main.py
<<<<<<< ORIGINAL
    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))),
    )
=======
    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))),
    )
    parser.add_argument(
        "--ctags",
        action="store_true",
        help=f"Use ctags for file listing (default: False, ${env_prefix}CTAGS)",
        default=bool(int(os.environ.get(f"{env_prefix}CTAGS", 0))),
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dry_run=args.dry_run,
    )
=======
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dry_run=args.dry_run,
        use_ctags=args.ctags,
    )
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dry_run=False,
    ):
=======
    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dry_run=False,
        use_ctags=False,
    ):
        self.use_ctags = use_ctags
>>>>>>> UPDATED
```

These changes add the `--ctags` argument, read the environment variable, and pass the `use_ctags` parameter to the `Coder` class.
2023-05-19 10:02:21 -07:00

133 lines
3.9 KiB
Python

import os
import sys
import argparse
from dotenv import load_dotenv
from aider.coder import Coder
from aider.io import InputOutput
def main(args=None, input=None, output=None):
if args is None:
args = sys.argv[1:]
load_dotenv()
env_prefix = "AIDER_"
parser = argparse.ArgumentParser(description="aider - chat with GPT about your code")
parser.add_argument(
"files",
metavar="FILE",
nargs="*",
help="a list of source code files (optional)",
)
parser.add_argument(
"--input-history-file",
metavar="INPUT_HISTORY_FILE",
default=os.environ.get(f"{env_prefix}INPUT_HISTORY_FILE", ".aider.input.history"),
help=(
"Specify the chat input history file (default: .aider.input.history,"
f" ${env_prefix}INPUT_HISTORY_FILE)"
),
)
parser.add_argument(
"--chat-history-file",
metavar="CHAT_HISTORY_FILE",
default=os.environ.get(f"{env_prefix}CHAT_HISTORY_FILE", ".aider.chat.history.md"),
help=(
"Specify the chat history file (default: .aider.chat.history.md,"
f" ${env_prefix}CHAT_HISTORY_FILE)"
),
)
parser.add_argument(
"--model",
metavar="MODEL",
default=os.environ.get(f"{env_prefix}MODEL", "gpt-4"),
help=f"Specify the model to use for the main chat (default: gpt-4, ${env_prefix}MODEL)",
)
parser.add_argument(
"-3",
action="store_const",
dest="model",
const="gpt-3.5-turbo",
help="Use gpt-3.5-turbo model for the main chat (not advised)",
)
parser.add_argument(
"--no-pretty",
action="store_false",
dest="pretty",
help=f"Disable pretty, colorized output (${env_prefix}PRETTY)",
default=bool(int(os.environ.get(f"{env_prefix}PRETTY", 1))),
)
parser.add_argument(
"--apply",
metavar="FILE",
help="Apply the changes from the given file instead of running the chat (debug)",
)
parser.add_argument(
"--no-auto-commits",
action="store_false",
dest="auto_commits",
help=f"Disable auto commit of changes (${env_prefix}AUTO_COMMITS)",
default=bool(int(os.environ.get(f"{env_prefix}AUTO_COMMITS", 1))),
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Perform a dry run without applying changes (default: False)",
default=False,
)
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))),
)
parser.add_argument(
"--ctags",
action="store_true",
help=f"Use ctags for file listing (default: False, ${env_prefix}CTAGS)",
default=bool(int(os.environ.get(f"{env_prefix}CTAGS", 0))),
)
parser.add_argument(
"--yes",
action="store_true",
help="Always say yes to every confirmation",
default=False,
)
args = parser.parse_args(args)
io = InputOutput(
args.pretty,
args.yes,
args.input_history_file,
args.chat_history_file,
input=input,
output=output,
)
io.tool(*sys.argv, log_only=True)
coder = Coder(
io,
main_model=args.model,
fnames=args.files,
pretty=args.pretty,
show_diffs=args.show_diffs,
auto_commits=args.auto_commits,
dry_run=args.dry_run,
use_ctags=args.ctags,
)
if args.auto_commits:
coder.commit(ask=True, prefix="wip: ", which="repo_files")
if args.apply:
with open(args.apply, "r") as f:
content = f.read()
coder.update_files(content, inp="")
return
coder.run()
if __name__ == "__main__":
status = main()
sys.exit(status)