mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
Refactor the cmd_ commands into Coder
This commit is contained in:
parent
475bc486d2
commit
4e9119a0e0
2 changed files with 16 additions and 11 deletions
|
@ -40,7 +40,7 @@ class Coder:
|
||||||
else:
|
else:
|
||||||
self.console = Console(force_terminal=True, no_color=True)
|
self.console = Console(force_terminal=True, no_color=True)
|
||||||
|
|
||||||
self.commands = Commands(self.console)
|
self.commands = Commands(self.console, self)
|
||||||
|
|
||||||
self.main_model = main_model
|
self.main_model = main_model
|
||||||
if main_model == "gpt-3.5-turbo":
|
if main_model == "gpt-3.5-turbo":
|
||||||
|
@ -475,3 +475,7 @@ class Coder:
|
||||||
self.last_modified = self.get_last_modified()
|
self.last_modified = self.get_last_modified()
|
||||||
|
|
||||||
return commit_hash, commit_message
|
return commit_hash, commit_message
|
||||||
|
|
||||||
|
def cmd_ls(self, args):
|
||||||
|
"List files and show their chat status"
|
||||||
|
print("ls")
|
||||||
|
|
|
@ -1,25 +1,23 @@
|
||||||
class Commands:
|
class Commands:
|
||||||
def __init__(self, console):
|
def __init__(self, console, obj):
|
||||||
self.console = console
|
self.console = console
|
||||||
|
self.obj = obj
|
||||||
|
|
||||||
def cmd_help(self, args):
|
def help(self):
|
||||||
"Show help about all commands"
|
"Show help about all commands"
|
||||||
commands = self.get_commands()
|
commands = self.get_commands()
|
||||||
for cmd in commands:
|
for cmd in commands:
|
||||||
cmd_method_name = f"cmd_{cmd[1:]}"
|
cmd_method_name = f"cmd_{cmd[1:]}"
|
||||||
cmd_method = getattr(self, cmd_method_name, None)
|
cmd_method = getattr(self.obj, cmd_method_name, None)
|
||||||
if cmd_method:
|
if cmd_method:
|
||||||
description = cmd_method.__doc__
|
description = cmd_method.__doc__
|
||||||
self.console.print(f"{cmd} {description}")
|
self.console.print(f"{cmd} {description}")
|
||||||
else:
|
else:
|
||||||
self.console.print(f"{cmd} No description available.")
|
self.console.print(f"{cmd} No description available.")
|
||||||
def cmd_ls(self, args):
|
|
||||||
"List files and show their chat status"
|
|
||||||
print("ls")
|
|
||||||
|
|
||||||
def get_commands(self):
|
def get_commands(self):
|
||||||
commands = []
|
commands = ["/help"]
|
||||||
for attr in dir(self):
|
for attr in dir(self.obj):
|
||||||
if attr.startswith("cmd_"):
|
if attr.startswith("cmd_"):
|
||||||
commands.append("/" + attr[4:])
|
commands.append("/" + attr[4:])
|
||||||
|
|
||||||
|
@ -27,7 +25,7 @@ class Commands:
|
||||||
|
|
||||||
def do_run(self, cmd_name, args):
|
def do_run(self, cmd_name, args):
|
||||||
cmd_method_name = f"cmd_{cmd_name}"
|
cmd_method_name = f"cmd_{cmd_name}"
|
||||||
cmd_method = getattr(self, cmd_method_name, None)
|
cmd_method = getattr(self.obj, cmd_method_name, None)
|
||||||
if cmd_method:
|
if cmd_method:
|
||||||
cmd_method(args)
|
cmd_method(args)
|
||||||
else:
|
else:
|
||||||
|
@ -45,6 +43,9 @@ class Commands:
|
||||||
matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)]
|
matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)]
|
||||||
|
|
||||||
if len(matching_commands) == 1:
|
if len(matching_commands) == 1:
|
||||||
|
if matching_commands[0] == "/help":
|
||||||
|
self.help()
|
||||||
|
else:
|
||||||
self.do_run(matching_commands[0][1:], rest_inp)
|
self.do_run(matching_commands[0][1:], rest_inp)
|
||||||
elif len(matching_commands) > 1:
|
elif len(matching_commands) > 1:
|
||||||
self.console.print("[red]Ambiguous command:", ", ".join(matching_commands))
|
self.console.print("[red]Ambiguous command:", ", ".join(matching_commands))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue