mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
aider: Modified run method to compare first word of input to commands and print partial matches or error message.
# Context: USER: in run, compare the first word to all the get_commands to figure out which cmd is being run. the first word may only be part of the name of a command. if it uniquely matches just one command, print 'run' and that command. if it matches more than one command, print the list of partial matches. if it matches none, print an error ASSISTANT: To implement the requested feature, we need to modify the `run` method in the `Commands` class. We will compare the first word of the input to the commands returned by `get_commands`. If there is a unique partial match, we will print 'run' and the command. If there are multiple partial matches, we will print the list of partial matches. If there are no matches, we will print an error message. Here are the changes to the `aider/commands.py` file: ```python aider/commands.py <<<<<<< ORIGINAL def run(self, inp, console): console.print('[red]', inp) words = inp.strip().split() ======= def run(self, inp, console): words = inp.strip().split() if not words: return first_word = words[0] all_commands = self.get_commands() matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)] if len(matching_commands) == 1: console.print('[green]run', matching_commands[0]) elif len(matching_commands) > 1: console.print('[yellow]Partial matches:', ', '.join(matching_commands)) else: console.print('[red]Error: Command not found') >>>>>>> UPDATED ```
This commit is contained in:
parent
2f85dc6733
commit
8b2fdd4b92
1 changed files with 13 additions and 1 deletions
|
@ -14,5 +14,17 @@ class Commands:
|
|||
return commands
|
||||
|
||||
def run(self, inp, console):
|
||||
console.print('[red]', inp)
|
||||
words = inp.strip().split()
|
||||
if not words:
|
||||
return
|
||||
|
||||
first_word = words[0]
|
||||
all_commands = self.get_commands()
|
||||
matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)]
|
||||
|
||||
if len(matching_commands) == 1:
|
||||
console.print('[green]run', matching_commands[0])
|
||||
elif len(matching_commands) > 1:
|
||||
console.print('[yellow]Partial matches:', ', '.join(matching_commands))
|
||||
else:
|
||||
console.print('[red]Error: Command not found')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue