Source

er-main / er / cmds.py

# -*- coding: utf-8 -*-
"""
    er.cmds
    ~~~~~~~

    Er base commands.

    :copyright: (c) 2010 by er authors.
    :license: GPLv3, see LICENSE.txt for more details.
"""


_er_registry = {}


class Command(object):
    """
    A command instance, to be used as a decorator.
    """

    def __init__(self, name=None):
        self.name = name

    def __call__(self, f):
        self.f = f
        if self.name is None:
            self.name = f.func_name
        _er_registry[self.name] = self
        return f

    def execute(self, ctx, repeat, range):
        return self.f(ctx)


# External Api

cmd = Command


def get(name):
    return _er_registry.get(name)


# movement commands

def go_up(ctx):
    pass