# Path: opennode/oms/endpoint/ssh/cmd/registry.py
# def commands():
# def get_command(name):
#         def __call__(self, *args):
#             def dist(a, b):
#     class UndefinedCommand(Cmd):
# 
# Path: opennode/oms/endpoint/ssh/cmd/directives.py
# class command(martian.Directive):
#     """Use this directive in a class in order to set its command name.
#     Only classes marked with this directive will be valid commands.
# 
#     """
# 
#     scope = martian.CLASS
#     store = martian.ONCE
#     default = None
# 
# class alias(martian.Directive):
#     """Use this directive in a class in order to add an alias.
#     TODO: make it work with multiple aliases.
# 
#     """
# 
#     scope = martian.CLASS
#     store = martian.ONCE
#     default = None


import martian
from opennode.oms.endpoint.ssh.cmd import registry
from opennode.oms.endpoint.ssh.cmd.base import Cmd
from opennode.oms.endpoint.ssh.cmd.directives import command, alias



class CmdGrokker(martian.ClassGrokker):
    martian.component(Cmd)
    martian.directive(command)

    def execute(self, class_, command, **kw):
        if command is None:
            return False

        registry.commands()[command] = class_
        class_.name = command
        return True


class AliasGrokker(martian.ClassGrokker):
    martian.component(Cmd)
    martian.directive(alias)

    def execute(self, class_, alias, **kwargs):
        if not getattr(class_, 'aliases', None):
            class_.aliases = []

        if alias:
            class_.aliases.append(alias)

# Path: opennode/oms/endpoint/ssh/cmd/registry.py
# def commands():
# def get_command(name):
#         def __call__(self, *args):
#             def dist(a, b):
#     class UndefinedCommand(Cmd):
# 
# Path: opennode/oms/endpoint/ssh/cmd/directives.py
# class command(martian.Directive):
#     """Use this directive in a class in order to set its command name.
#     Only classes marked with this directive will be valid commands.
# 
#     """
# 
#     scope = martian.CLASS
#     store = martian.ONCE
#     default = None
# 
# class alias(martian.Directive):
#     """Use this directive in a class in order to add an alias.
#     TODO: make it work with multiple aliases.
# 
#     """
# 
#     scope = martian.CLASS
#     store = martian.ONCE
#     default = None


# Path: opennode/oms/endpoint/ssh/cmd/grokkers.py
import martian
from opennode.oms.endpoint.ssh.cmd import registry
from opennode.oms.endpoint.ssh.cmd.base import Cmd
from opennode.oms.endpoint.ssh.cmd.directives import command, alias




class CmdGrokker(martian.ClassGrokker):
    martian.component(Cmd)
    martian.directive(command)

    def execute(self, class_, command, **kw):
        if command is None:
            return False

        registry.commands()[command] = class_
        class_.name = command
        return True


class AliasGrokker(martian.ClassGrokker):
    martian.component(Cmd)
    martian.directive(alias)

    def execute(self, class_, alias, **kwargs):
        if not getattr(class_, 'aliases', None):
            class_.aliases = []

        if alias:
            class_.aliases.append(alias)

            registry.commands()[alias] = class_