summaryrefslogtreecommitdiff
path: root/examples/hooks.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-28 14:42:09 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-28 14:42:09 -0400
commitf8a285b6dc32737337a6b54b028d068fe278e3df (patch)
tree0d53dd98683878e6d83d33e9779c20756cdd131d /examples/hooks.py
parentd21ecf17dc24e4e3802e7359d2480af835e09ddf (diff)
downloadcmd2-git-f8a285b6dc32737337a6b54b028d068fe278e3df.tar.gz
Updated abbreviation example to use new cmd2 function to resolve command functions
Diffstat (limited to 'examples/hooks.py')
-rw-r--r--examples/hooks.py10
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