mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 22:04:59 +00:00
Added Commands.console
This commit is contained in:
parent
c368737e70
commit
6076cd0fb7
2 changed files with 15 additions and 12 deletions
|
@ -28,7 +28,6 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||||
|
|
||||||
class Coder:
|
class Coder:
|
||||||
fnames = set()
|
fnames = set()
|
||||||
commands = Commands()
|
|
||||||
|
|
||||||
last_modified = 0
|
last_modified = 0
|
||||||
repo = None
|
repo = None
|
||||||
|
@ -41,6 +40,8 @@ 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.main_model = main_model
|
self.main_model = main_model
|
||||||
if main_model == "gpt-3.5-turbo":
|
if main_model == "gpt-3.5-turbo":
|
||||||
self.console.print(
|
self.console.print(
|
||||||
|
@ -184,7 +185,7 @@ class Coder:
|
||||||
inp = get_input(self.history_file, self.fnames, self.commands)
|
inp = get_input(self.history_file, self.fnames, self.commands)
|
||||||
|
|
||||||
if inp.startswith("/"):
|
if inp.startswith("/"):
|
||||||
self.commands.run(inp, self.console)
|
self.commands.run(inp)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.num_control_c = 0
|
self.num_control_c = 0
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
|
|
||||||
class Commands:
|
class Commands:
|
||||||
def __init__(self, console):
|
def __init__(self, console):
|
||||||
self.console = console
|
self.console = console
|
||||||
|
|
||||||
def cmd_help(self, args):
|
def cmd_help(self, args):
|
||||||
print('help')
|
print("help")
|
||||||
|
|
||||||
def cmd_ls(self, args):
|
def cmd_ls(self, args):
|
||||||
print('ls')
|
print("ls")
|
||||||
|
|
||||||
def get_commands(self):
|
def get_commands(self):
|
||||||
commands = []
|
commands = []
|
||||||
for attr in dir(self):
|
for attr in dir(self):
|
||||||
if attr.startswith("cmd_"):
|
if attr.startswith("cmd_"):
|
||||||
commands.append('/' + attr[4:])
|
commands.append("/" + attr[4:])
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
|
@ -21,22 +22,23 @@ class Commands:
|
||||||
if cmd_method:
|
if cmd_method:
|
||||||
cmd_method(args)
|
cmd_method(args)
|
||||||
else:
|
else:
|
||||||
print(f"Error: Command {cmd_name} not found.")
|
self.console.print(f"Error: Command {cmd_name} not found.")
|
||||||
def run(self, inp, console):
|
|
||||||
|
def run(self, inp):
|
||||||
words = inp.strip().split()
|
words = inp.strip().split()
|
||||||
if not words:
|
if not words:
|
||||||
return
|
return
|
||||||
|
|
||||||
first_word = words[0]
|
first_word = words[0]
|
||||||
rest_inp = inp[len(words[0]):]
|
rest_inp = inp[len(words[0]) :]
|
||||||
|
|
||||||
all_commands = self.get_commands()
|
all_commands = self.get_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:
|
||||||
console.print('[green]run', matching_commands[0])
|
self.console.print("[green]run", matching_commands[0])
|
||||||
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:
|
||||||
console.print('[red]Ambiguous command:', ', '.join(matching_commands))
|
self.console.print("[red]Ambiguous command:", ", ".join(matching_commands))
|
||||||
else:
|
else:
|
||||||
console.print(f'[red]Error: {first_word} is not a valid command.')
|
self.console.print(f"[red]Error: {first_word} is not a valid command.")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue