mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 09:44:59 +00:00
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:
parent
59d486c89c
commit
b267f6e79d
1 changed files with 6 additions and 0 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue