diff options
author | kotfu <kotfu@kotfu.net> | 2018-06-21 15:13:52 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-06-21 15:13:52 -0600 |
commit | 1cd46fd53c698f062995c2c45db57c07285a6f46 (patch) | |
tree | 4f306bf01c328ba32e14b5ff96d127384b111a91 | |
parent | c9ea3a749f7febb6dfe0f36001457e3907524ee7 (diff) | |
download | cmd2-git-1cd46fd53c698f062995c2c45db57c07285a6f46.tar.gz |
Revise precommand hooks to use `data` parameter
-rw-r--r-- | cmd2/cmd2.py | 6 | ||||
-rw-r--r-- | tests/test_plugin.py | 14 |
2 files changed, 10 insertions, 10 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 75814b14..bd56fe71 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1715,10 +1715,10 @@ class Cmd(cmd.Cmd): self._last_result = None # precommand hooks + data = plugin.PrecommandData(statement) for func in self._precmd_hooks: - data = plugin.PrecommandData(statement) - result = func(data) - statement = result.statement + data = func(data) + statement = data.statement # call precmd() for compatibility with cmd.Cmd statement = self.precmd(statement) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 98ad30ee..1f07f177 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -126,19 +126,19 @@ class Plugin: "A precommand hook with too many parameters" return one - def precmd_hook_no_parameter_type(self, mydat) -> plugin.PrecommandData: + def precmd_hook_no_parameter_type(self, data) -> plugin.PrecommandData: "A precommand hook with no type annotation on the parameter" - return mydat + return data - def precmd_hook_wrong_parameter_type(self, mydat: str) -> plugin.PrecommandData: + def precmd_hook_wrong_parameter_type(self, data: str) -> plugin.PrecommandData: "A precommand hook with the incorrect type annotation on the parameter" - return mydat + return data - def precmd_hook_no_return_type(self, mydat: plugin.PrecommandData): + def precmd_hook_no_return_type(self, data: plugin.PrecommandData): "A precommand hook with no type annotation on the return value" - return mydat + return data - def precmd_hook_wrong_return_type(self, mydat: plugin.PrecommandData) -> cmd2.Statement: + def precmd_hook_wrong_return_type(self, data: plugin.PrecommandData) -> cmd2.Statement: return self.statement_parser.parse('hi there') |