diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-09-16 11:17:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-16 11:17:21 -0400 |
commit | f10674e6db245da5b4062aef3391d54c33277255 (patch) | |
tree | d00e6541e574b49c9c15a063faeb6c13ada47a6e /cmd2/cmd2.py | |
parent | 693ec59719edc4384739392a0daea73c922b91c3 (diff) | |
parent | 92fb7902b3903d602355d2159dccddbc01b81ee2 (diff) | |
download | cmd2-git-f10674e6db245da5b4062aef3391d54c33277255.tar.gz |
Merge pull request #775 from python-cmd2/dynamic_commands.py
Added a basic example for dynamically adding do_* commands in a loop
Diffstat (limited to 'cmd2/cmd2.py')
-rwxr-xr-x | cmd2/cmd2.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index a0a49a51..610ec897 100755 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1596,6 +1596,10 @@ class Cmd(cmd.Cmd): tokens, _ = self.tokens_for_completion(line, begidx, endidx) return completer.complete_command(tokens, text, line, begidx, endidx) + def get_names(self): + """Return an alphabetized list of names comprising the attributes of the cmd2 class instance.""" + return dir(self) + def get_all_commands(self) -> List[str]: """Return a list of all commands""" return [name[len(COMMAND_FUNC_PREFIX):] for name in self.get_names() |