From 8b2fdd4b92cdd5d0a85500efa1b6a30006686319 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 11:12:17 -0700 Subject: [PATCH] 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 ``` --- aider/commands.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/aider/commands.py b/aider/commands.py index 2cc09cc1f..eb3a5f534 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -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')