From e33ee46fe17032e58f1d96e177c9fab3ba035abf Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 11:16:56 -0700 Subject: [PATCH] aider: Implemented `do_run` method to invoke the correct `cmd_` method function based on the provided `cmd_name` and passing it the `args`. # Context: USER: implement do_run. use the cmd_name (which has no /) to invoke the correct cmd_ method function, passing it the args. ASSISTANT: To implement the `do_run` method, we will use the `cmd_name` to find the corresponding `cmd_` method and invoke it with the provided `args`. We can use the `getattr` function to get the method by its name and then call it with the `args`. Here are the changes to the `aider/commands.py` file: ```python aider/commands.py <<<<<<< ORIGINAL def do_run(self, cmd_name, args): pass ======= def do_run(self, cmd_name, args): cmd_method_name = f"cmd_{cmd_name}" cmd_method = getattr(self, cmd_method_name, None) if cmd_method: cmd_method(args) else: print(f"Error: Command {cmd_name} not found.") >>>>>>> UPDATED ``` --- aider/commands.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 0fba2b68b..1234141c6 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -1,8 +1,8 @@ class Commands: - def cmd_help(self): + def cmd_help(self, args): print('help') - def cmd_ls(self): + def cmd_ls(self, args): print('ls') def get_commands(self): @@ -14,8 +14,12 @@ class Commands: return commands def do_run(self, cmd_name, args): - pass - + cmd_method_name = f"cmd_{cmd_name}" + cmd_method = getattr(self, cmd_method_name, None) + if cmd_method: + cmd_method(args) + else: + print(f"Error: Command {cmd_name} not found.") def run(self, inp, console): words = inp.strip().split() if not words: