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
```
This commit is contained in:
Paul Gauthier 2023-05-10 11:16:56 -07:00
parent 126b5e1f3b
commit e33ee46fe1

View file

@ -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: