From c5cf21e80245288c8af16229743470106bffb99b Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Aug 29 2014 21:39:12 +0000 Subject: command_manager: allow for recursive aliases (w/o guards) Signed-off-by: Jan Pokorný --- diff --git a/command.py b/command.py index 56349c2..cb2ff98 100644 --- a/command.py +++ b/command.py @@ -39,6 +39,7 @@ log = logging.getLogger(__name__) protodecl = lambda x: len(x) == 2 and isinstance(x[0], Filter) + class CommandError(ClufterError): pass @@ -580,10 +581,11 @@ class CommandAlias(object): # XXX really pass mutable cmds dict? use_obj = fnc(cmds, system.lower(), tuple(system_extra.lower().split(','))) - if not isinstance(use_obj, Command): - assert isinstance(use_obj, basestring) + if isinstance(use_obj, basestring): use_obj = cmds[use_obj] assert isinstance(use_obj, Command) + else: + assert issubclass(use_obj, (nonetype, Command, CommandAlias)) return use_obj attrs = { diff --git a/command_manager.py b/command_manager.py index 40b0a31..253c4ef 100644 --- a/command_manager.py +++ b/command_manager.py @@ -8,10 +8,11 @@ __author__ = "Jan Pokorný " import logging from textwrap import wrap -from .command import commands, CommandAlias +from .command import commands, Command, CommandAlias from .error import ClufterError, ClufterPlainError, \ EC from .plugin_registry import PluginManager +from .utils import nonetype from .utils_func import apply_preserving_depth, \ apply_aggregation_preserving_depth, \ apply_intercalate, \ @@ -90,7 +91,13 @@ class CommandManager(PluginManager): assert issubclass(alias_singleton, CommandAlias) resolved = alias_singleton(commands, system, system_extra) if resolved is None or resolved not in inverse_commands: - if resolved: + if issubclass(resolved, (Command, CommandAlias)): + commands[cmd_name] = resolved + if issubclass(resolved, CommandAlias): + # alias to alias recursion -> just repeat the cycle + aliases.append(resolved) + continue + elif resolved: log.warning("Resolve at `{0}' alias: target unrecognized" .format(cmd_name)) commands.pop(cmd_name)