MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / abbrev_hook

Method abbrev_hook

examples/hooks.py:80–89  ·  view source on GitHub ↗

Accept unique abbreviated commands.

(self, data: cmd2.plugin.PostparsingData)

Source from the content-addressed store, hash-verified

78 return data
79
80 def abbrev_hook(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData:
81 """Accept unique abbreviated commands."""
82 func = self.get_command_func(data.statement.command)
83 if func is None:
84 # check if the entered command might be an abbreviation
85 possible_cmds = [cmd for cmd in self.get_all_commands() if cmd.startswith(data.statement.command)]
86 if len(possible_cmds) == 1:
87 raw = data.statement.raw.replace(data.statement.command, possible_cmds[0], 1)
88 data.statement = self.statement_parser.parse(raw)
89 return data
90
91 def proof_hook(self, data: cmd2.plugin.PostcommandData) -> cmd2.plugin.PostcommandData:
92 """Update the shell prompt with the new raw statement after postparsing hooks are finished."""

Callers

nothing calls this directly

Calls 3

get_command_funcMethod · 0.80
parseMethod · 0.80
get_all_commandsMethod · 0.45

Tested by

no test coverage detected