diff options
Diffstat (limited to 'examples/hooks.py')
-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 |