mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
Add command line argument for history file with environment variable default and pass it to Coder class.
# 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.
This commit is contained in:
parent
fed71fef4c
commit
fd127076df
1 changed files with 10 additions and 4 deletions
12
coder.py
12
coder.py
|
@ -32,9 +32,9 @@ class Coder:
|
|||
fnames = dict()
|
||||
last_modified = 0
|
||||
repo = None
|
||||
history_file = ".coder.history"
|
||||
|
||||
def __init__(self, main_model, files, pretty):
|
||||
def __init__(self, main_model, files, pretty, history_file=".coder.history"):
|
||||
self.history_file = history_file
|
||||
try:
|
||||
readline.read_history_file(self.history_file)
|
||||
except FileNotFoundError:
|
||||
|
@ -572,6 +572,12 @@ def main():
|
|||
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)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--model",
|
||||
metavar="MODEL",
|
||||
|
@ -615,7 +621,7 @@ def main():
|
|||
fnames = args.files
|
||||
pretty = args.pretty
|
||||
|
||||
coder = Coder(args.model, fnames, pretty)
|
||||
coder = Coder(args.model, fnames, pretty, args.history_file)
|
||||
coder.commit(ask=not args.commit_dirty, prefix="WIP: ")
|
||||
|
||||
if args.apply:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue