aider: Added get_commands() method to Commands class.

# Context:
USER: add get_commands() to Commands. it should find all functions in the class like `cmd_xxx` and return a list of their names without the cmd_ prefix.
ASSISTANT: To add the `get_commands()` method to the `Commands` class, you can use the `dir()` function to get all the attributes of the class and then filter the ones that start with `cmd_`. Here's the change:

```python
aider/getinput.py
<<<<<<< ORIGINAL
class Commands:
    def cmd_help(self):
        print('help')
    def cmd_ls(self):
        print('ls')
=======
class Commands:
    def cmd_help(self):
        print('help')
    def cmd_ls(self):
        print('ls')

    def get_commands(self):
        commands = []
        for attr in dir(self):
            if attr.startswith("cmd_"):
                commands.append(attr[4:])
        return commands
>>>>>>> UPDATED
```

Now, the `Commands` class has a `get_commands()` method that returns a list of command names without the `cmd_` prefix.
This commit is contained in:
Paul Gauthier 2023-05-10 10:51:13 -07:00
parent 59d486c89c
commit b267f6e79d

View file

@ -18,6 +18,12 @@ class Commands:
def cmd_ls(self):
print('ls')
def get_commands(self):
commands = []
for attr in dir(self):
if attr.startswith("cmd_"):
commands.append(attr[4:])
return commands
class FileContentCompleter(Completer):
def __init__(self, fnames):