From 4e557baad4a1a30ecb103be52b3a076b6e4e5bf9 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 26 May 2023 12:21:43 -0700 Subject: [PATCH] cleaned up /exit, normalized /help --- aider/commands.py | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 962e81b6e..00fd36182 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -3,7 +3,6 @@ import os import git import subprocess import shlex -from rich.prompt import Confirm from prompt_toolkit.completion import Completion from aider import prompts @@ -17,20 +16,8 @@ class Commands: if inp[0] == "/": return True - def help(self): - "Show help about all commands" - commands = self.get_commands() - for cmd in commands: - cmd_method_name = f"cmd_{cmd[1:]}" - cmd_method = getattr(self, cmd_method_name, None) - if cmd_method: - description = cmd_method.__doc__ - self.io.tool(f"{cmd} {description}") - else: - self.io.tool(f"{cmd} No description available.") - def get_commands(self): - commands = ["/help", "/exit"] + commands = [] for attr in dir(self): if attr.startswith("cmd_"): commands.append("/" + attr[4:]) @@ -63,17 +50,15 @@ class Commands: all_commands = self.get_commands() matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)] if len(matching_commands) == 1: - if matching_commands[0] == "/help": - self.help() - else: - return self.do_run(matching_commands[0][1:], rest_inp) + 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() + self.io.tool_error(f"Ambiguous command: {', '.join(matching_commands)}") else: self.io.tool_error(f"Error: {first_word} is not a valid command.") + # any method called cmd_xxx becomes a command automatically. + # each one must take an args param. + def cmd_commit(self, args): "Commit edits to the repo made outside the chat (commit message optional)" @@ -254,7 +239,7 @@ class Commands: ) return msg - def cmd_exit(self): + def cmd_exit(self, args): "Exit the application" sys.exit() @@ -281,3 +266,15 @@ class Commands: self.io.tool("\nRepo files not in the chat:\n") for file in other_files: self.io.tool(f" {file}") + + def cmd_help(self, args): + "Show help about all commands" + commands = sorted(self.get_commands()) + for cmd in commands: + cmd_method_name = f"cmd_{cmd[1:]}" + cmd_method = getattr(self, cmd_method_name, None) + if cmd_method: + description = cmd_method.__doc__ + self.io.tool(f"{cmd} {description}") + else: + self.io.tool(f"{cmd} No description available.")