summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRajath Agasthya <rajathagasthya@gmail.com>2017-06-29 01:09:14 -0700
committerRajath Agasthya <rajathagasthya@gmail.com>2017-07-06 15:39:39 -0700
commitc6d258da1ca18b9330f5b0554f57e8f67542b9fe (patch)
treea7baa3be278e84f416f1b589a6656053e4c52b3b
parent0c378ba96fbbf7475a9e440417d018b42734c4d9 (diff)
downloadcliff-c6d258da1ca18b9330f5b0554f57e8f67542b9fe.tar.gz
Run hooks for DisplayCommandBase
Command base class has provisions to run hooks for a command in its run() method. We need to do the same for the DisplayCommandBase class since it does not call super().run() Change-Id: Ic5481523d4bd919fe7fb10e00330dea2ff688ec4
-rw-r--r--cliff/command.py28
-rw-r--r--cliff/display.py2
2 files changed, 28 insertions, 2 deletions
diff --git a/cliff/command.py b/cliff/command.py
index ac5e23a..1c6ac48 100644
--- a/cliff/command.py
+++ b/cliff/command.py
@@ -133,12 +133,36 @@ class Command(object):
Return the value returned by :meth:`take_action` or 0.
"""
+ self._run_before_hooks(parsed_args)
+ return_code = self.take_action(parsed_args) or 0
+ self._run_after_hooks(parsed_args, return_code)
+ return return_code
+
+ def _run_before_hooks(self, parsed_args):
+ """Calls before() method of the hooks.
+
+ This method is intended to be called from the run() method before
+ take_action() is called.
+
+ This method should only be overriden by developers creating new
+ command base classes and only if it is necessary to have different
+ hook processing behavior.
+ """
for hook in self._hooks:
hook.obj.before(parsed_args)
- return_code = self.take_action(parsed_args) or 0
+
+ def _run_after_hooks(self, parsed_args, return_code):
+ """Calls after() method of the hooks.
+
+ This method is intended to be called from the run() method after
+ take_action() is called.
+
+ This method should only be overriden by developers creating new
+ command base classes and only if it is necessary to have different
+ hook processing behavior.
+ """
for hook in self._hooks:
hook.obj.after(parsed_args, return_code)
- return return_code
class _SmartHelpFormatter(_argparse.HelpFormatter):
diff --git a/cliff/display.py b/cliff/display.py
index 0c69352..1625a9d 100644
--- a/cliff/display.py
+++ b/cliff/display.py
@@ -108,8 +108,10 @@ class DisplayCommandBase(command.Command):
return columns_to_include, selector
def run(self, parsed_args):
+ self._run_before_hooks(parsed_args)
self.formatter = self._formatter_plugins[parsed_args.formatter].obj
column_names, data = self.take_action(parsed_args)
+ self._run_after_hooks(parsed_args, (column_names, data))
self.produce_output(parsed_args, column_names, data)
return 0