summaryrefslogtreecommitdiffstats
path: root/command_manager.py
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2014-08-26 18:23:28 +0200
committerJan Pokorný <jpokorny@redhat.com>2014-08-26 18:23:28 +0200
commitb23cc121c3d7866dea8b559e08142d1dc229fb9e (patch)
treeb15f159c2f63a3e9b7430bbd076d278345b64cce /command_manager.py
parent21f7955f2814dad3444ce54df97388c0aa78e340 (diff)
downloadclufter-b23cc121c3d7866dea8b559e08142d1dc229fb9e.tar.gz
clufter-b23cc121c3d7866dea8b559e08142d1dc229fb9e.tar.xz
clufter-b23cc121c3d7866dea8b559e08142d1dc229fb9e.zip
command_manager: add `implicit` as a shortcut constructor
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'command_manager.py')
-rw-r--r--command_manager.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/command_manager.py b/command_manager.py
index 6dd068e..40b0a31 100644
--- a/command_manager.py
+++ b/command_manager.py
@@ -34,6 +34,7 @@ class CommandNotFoundError(ClufterPlainError):
class CommandManager(PluginManager):
"""Class responsible for commands routing to filters or other actions"""
_default_registry = commands
+ _implicit = None
def _init_handle_plugins(self, commands, flt_mgr, *args):
log.debug("Commands before resolving: {0}".format(commands))
@@ -42,6 +43,19 @@ class CommandManager(PluginManager):
def __iter__(self):
return self._commands.itervalues()
+ @classmethod
+ def implicit(cls, *args):
+ """Ad-hoc simply-cached construction of "implicit" manager's chain"""
+ if cls._implicit and not args:
+ implicit = cls._implicit
+ else:
+ from .filter_manager import FilterManager
+ from .format_manager import FormatManager
+ implicit = cls(FilterManager(FormatManager()), *args)
+ if not args:
+ cls._implicit = implicit
+ return implicit
+
@staticmethod
def _resolve(filters, commands, system='', system_extra=''):
# name -> (cmd obj if not alias or resolvable name)