diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-09-28 14:42:09 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-09-28 14:42:09 -0400 |
commit | f8a285b6dc32737337a6b54b028d068fe278e3df (patch) | |
tree | 0d53dd98683878e6d83d33e9779c20756cdd131d | |
parent | d21ecf17dc24e4e3802e7359d2480af835e09ddf (diff) | |
download | cmd2-git-f8a285b6dc32737337a6b54b028d068fe278e3df.tar.gz |
Updated abbreviation example to use new cmd2 function to resolve command functions
-rw-r--r-- | examples/hooks.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/examples/hooks.py b/examples/hooks.py index 3d11457a..b6f6263e 100644 --- a/examples/hooks.py +++ b/examples/hooks.py @@ -84,12 +84,12 @@ class CmdLineApp(cmd2.Cmd): def abbrev_hook(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData: """Accept unique abbreviated commands""" - target = 'do_' + data.statement.command - if target not in dir(self): + func = self.cmd_func(data.statement.command) + if func is None: # check if the entered command might be an abbreviation - funcs = [func for func in self.keywords if func.startswith(data.statement.command)] - if len(funcs) == 1: - raw = data.statement.raw.replace(data.statement.command, funcs[0], 1) + possible_cmds = [cmd for cmd in self.keywords if cmd.startswith(data.statement.command)] + if len(possible_cmds) == 1: + raw = data.statement.raw.replace(data.statement.command, possible_cmds[0], 1) data.statement = self.statement_parser.parse(raw) return data |