From b267f6e79d6fe0a7ad42babe939687ac160b1dbd Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 10:51:13 -0700 Subject: [PATCH] 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. --- aider/getinput.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aider/getinput.py b/aider/getinput.py index 3b61dc78c..e58a44af7 100644 --- a/aider/getinput.py +++ b/aider/getinput.py @@ -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):