Skip to content

Commit f8a285b

Browse files
committed
Updated abbreviation example to use new cmd2 function to resolve command functions
1 parent d21ecf1 commit f8a285b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/hooks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ def downcase_hook(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.Postpa
8484

8585
def abbrev_hook(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData:
8686
"""Accept unique abbreviated commands"""
87-
target = 'do_' + data.statement.command
88-
if target not in dir(self):
87+
func = self.cmd_func(data.statement.command)
88+
if func is None:
8989
# check if the entered command might be an abbreviation
90-
funcs = [func for func in self.keywords if func.startswith(data.statement.command)]
91-
if len(funcs) == 1:
92-
raw = data.statement.raw.replace(data.statement.command, funcs[0], 1)
90+
possible_cmds = [cmd for cmd in self.keywords if cmd.startswith(data.statement.command)]
91+
if len(possible_cmds) == 1:
92+
raw = data.statement.raw.replace(data.statement.command, possible_cmds[0], 1)
9393
data.statement = self.statement_parser.parse(raw)
9494
return data
9595

0 commit comments

Comments
 (0)