mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 16:25:00 +00:00
aider is AI pair programming in your terminal
https://aider.chat/
![]() # Context: USER: make a cmd line arg with environ default for history_file, pass it into Coder.__init__ ASSISTANT: To add a command line argument for the history file with an environment variable default, you can update the `argparse` section in the `main()` function. Here's the change: ```python coder.py <<<<<<< ORIGINAL parser = argparse.ArgumentParser(description="Chat with GPT about code") parser.add_argument( "files", metavar="FILE", nargs="+", help="a list of source code files", ) ======= parser = argparse.ArgumentParser(description="Chat with GPT about code") parser.add_argument( "files", metavar="FILE", nargs="+", help="a list of source code files", ) parser.add_argument( "--history-file", metavar="HISTORY_FILE", default=os.environ.get("CODER_HISTORY_FILE", ".coder.history"), help="Specify the history file (default: .coder.history or value from CODER_HISTORY_FILE environment variable)", ) >>>>>>> UPDATED ``` Next, pass the `history_file` argument to the `Coder` class in the `main()` function: ```python coder.py <<<<<<< ORIGINAL coder = Coder(args.model, fnames, pretty) ======= coder = Coder(args.model, fnames, pretty, args.history_file) >>>>>>> UPDATED ``` Finally, update the `Coder` class to accept the `history_file` argument and use it in the `__init__` method: ```python coder.py <<<<<<< ORIGINAL class Coder: fnames = dict() last_modified = 0 repo = None history_file = ".coder.history" def __init__(self, main_model, files, pretty): ======= class Coder: fnames = dict() last_modified = 0 repo = None def __init__(self, main_model, files, pretty, history_file=".coder.history"): self.history_file = history_file >>>>>>> UPDATED ``` Now, the history file can be specified using the `--history-file` command line argument or the `CODER_HISTORY_FILE` environment variable. |
||
---|---|---|
.flake8 | ||
.pre-commit-config.yaml | ||
coder.py | ||
dump.py | ||
prompts.py |