From c40d763bce1cd463de53477925c9bfd6028f38f1 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 26 May 2023 12:16:59 -0700 Subject: [PATCH] aider: Added `/exit` command to `aider/commands.py`. # Context: USER: add an /exit command which calls sys.exit ASSISTANT: To add an `/exit` command, we need to modify the `commands.py` file to add a new command method and update the `is_command` and `run` methods to recognize and execute the new command. We also need to import `sys` to use `sys.exit()`. Here are the changes: ```python aider/commands.py <<<<<<< ORIGINAL from . import io ======= import sys from . import io >>>>>>> UPDATED ``` ```python aider/commands ^C KeyboardInterrupt USER: I added the content of these additional files: aider/commands.py ASSISTANT: I apologize for the confusion. Here are the changes to add the `/exit` command to the `aider/commands.py` file: ```python aider/commands.py <<<<<<< ORIGINAL import os import git import subprocess import shlex ======= import sys import os import git import subprocess import shlex >>>>>>> UPDATED ``` ```python aider/commands.py <<<<<<< ORIGINAL commands = ["/help"] ======= commands = ["/help", "/exit"] >>>>>>> UPDATED ``` ```python aider/commands.py <<<<<<< ORIGINAL else: self.io.tool_error(f"Error: {first_word} is not a valid command.") ======= elif first_word == "/exit": self.cmd_exit() else: self.io.tool_error(f"Error: {first_word} is not a valid command.") >>>>>>> UPDATED ``` ```python aider/commands.py <<<<<<< ORIGINAL def cmd_ls(self, args): "List all known files and those included in the chat session" ======= def cmd_exit(self): "Exit the application" sys.exit() def cmd_ls(self, args): "List all known files and those included in the chat session" >>>>>>> UPDATED ``` These changes will add the `/exit` command to the list of commands, recognize it when entered, and call the `cmd_exit` method to exit the application using `sys.exit()`. --- aider/commands.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aider/commands.py b/aider/commands.py index 4e1b88067..962e81b6e 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -1,3 +1,4 @@ +import sys import os import git import subprocess @@ -29,7 +30,7 @@ class Commands: self.io.tool(f"{cmd} No description available.") def get_commands(self): - commands = ["/help"] + commands = ["/help", "/exit"] for attr in dir(self): if attr.startswith("cmd_"): commands.append("/" + attr[4:]) @@ -68,6 +69,8 @@ class Commands: return self.do_run(matching_commands[0][1:], rest_inp) elif len(matching_commands) > 1: self.io.tool_error("Ambiguous command: ', '.join(matching_commands)}") + elif first_word == "/exit": + self.cmd_exit() else: self.io.tool_error(f"Error: {first_word} is not a valid command.") @@ -251,6 +254,10 @@ class Commands: ) return msg + def cmd_exit(self): + "Exit the application" + sys.exit() + def cmd_ls(self, args): "List all known files and those included in the chat session"