# -*- coding: UTF-8 -*- ''' 命令行分发路由 ''' def dispatch(actions, targets): """ 分发命令行 action """ action_len = len(actions) print(action_len) if action_len < 2: if targets.get('run') != None: print(f"[命令路由执行]:", '->'.join(actions)) targets['run']() else: print('action not found') return index = 0 next = targets action = actions[index] print(f"[命令路由中..]: {actions[0]}") print(actions) while action_len >= index: if type(next) == type({}): if index == action_len: if next.get('run') is not None: print(f"[命令路由执行]:", '->'.join(actions)) next['run']() break else: print('not found') action = actions[index] if next.get(action) is not None: print(f"[命令路由中..]: {action}") next = next[action] index += 1 else: print("[命令路由错误]: 未找到支持的命令行路由:", '->'.join(actions), ", obj:", next) index += 1 else: print(f"[命令路由执行]:", '->'.join(actions)) next() index += 1 break