# Path: sen/tui/commands/base.py
# class Command:
#     # command name, unique identifier, used also in prompt
#     name = ""
#     # message explaining what's about to happen
#     pre_info_message = ""
#     # message explaining what has happened
#     post_info_message = ""
#     # how long it takes to run the command - in which queue it should be executed
#     priority = None
#     # used in help message
#     description = ""
#     # define options
#     options_definitions = []
#     # define arguments
#     arguments_definitions = []
#     # command is available under these aliases
#     aliases = []
# 
#     def __init__(self, ui=None, docker_backend=None, docker_object=None, buffer=None, size=None):
#         """
# 
#         :param ui:
#         :param docker_backend:
#         :param docker_object:
#         :param buffer:
#         """
#         logger.debug(
#             "command %r initialized: ui=%r, docker_backend=%r, docker_object=%r, buffer=%r",
#             self.name, ui, docker_backend, docker_object, buffer)
#         self.ui = ui
#         self.docker_backend = docker_backend
#         self.docker_object = docker_object
#         self.buffer = buffer
#         self.size = size
#         self.argument_processor = ArgumentProcessor(self.options_definitions,
#                                                     self.arguments_definitions)
#         self.arguments = None
# 
#     def process_args(self, arguments):
#         """
# 
#         :param arguments: dict
#         :return:
#         """
#         given_arguments = self.argument_processor.process(arguments)
#         logger.info("given arguments = %s", given_arguments)
#         self.arguments = CommandArgumentsGetter(given_arguments)
# 
#     def run(self):
#         raise NotImplementedError()
# 
# class Option(ArgumentBase):
#     """
#     options alter behavior, are not positional
#     """
#     def __init__(self, name, description, action=true_action, aliases=None, default=None):
#         super().__init__(name, description, action=action, default=default)
#         self.aliases = aliases or []
# 
#     def __str__(self):
#         return "{} default={} action=\"{}\" aliases={}".format(
#             self.name, self.default, self.action, self.aliases
#         )
# 
#     def __unicode__(self):
#         return self.__str__()
# 
# class Commander:
#     """
#     Responsible for managing commands: it's up to workers to do the commands actually.
#     """
#     def __init__(self, ui, docker_backend):
#         self.ui = ui
#         self.docker_backend = docker_backend
#         self.modifier_keys_pressed = []
#         logger.debug("available commands: %s", commands_mapping)
# 
#     def get_command(self, command_input, docker_object=None, buffer=None, size=None):
#         """
#         return command instance which is the actual command to be executed
# 
#         :param command_input: str, command name and its args: "command arg arg2=val opt"
#         :param docker_object:
#         :param buffer:
#         :param size: tuple, so we can call urwid.keypress(size, ...)
#         :return: instance of Command
#         """
#         logger.debug("get command for command input %r", command_input)
# 
#         if not command_input:
#             # noop, don't do anything
#             return
# 
#         if command_input[0] in ["/"]:  # we could add here !, @, ...
#             command_name = command_input[0]
#             unparsed_command_args = shlex.split(command_input[1:])
#         else:
#             command_input_list = shlex.split(command_input)
#             command_name = command_input_list[0]
#             unparsed_command_args = command_input_list[1:]
# 
#         try:
#             CommandClass = commands_mapping[command_name]
#         except KeyError:
#             logger.info("no such command: %r", command_name)
#             raise NoSuchCommand("There is no such command: %s" % command_name)
#         else:
#             cmd = CommandClass(ui=self.ui, docker_backend=self.docker_backend,
#                                docker_object=docker_object, buffer=buffer, size=size)
#             cmd.process_args(unparsed_command_args)
#             return cmd
# 
#     def get_command_input_by_key(self, key):
#         logger.debug("get command input for key %r", key)
# 
#         modifier_keys = ["g"]  # FIXME: we should be able to figure this out from existing keybinds
# 
#         inp = "".join(self.modifier_keys_pressed) + key
# 
#         try:
#             command_input = self.ui.current_buffer.get_keybinds()[inp]
#         except KeyError:
#             if key in modifier_keys:
#                 # TODO: inform user maybe
#                 self.modifier_keys_pressed.append(key)
#                 logger.info("modifier keys pressed: %s", self.modifier_keys_pressed)
#                 return
#             else:
#                 logger.info("no such keybind: %r", inp)
#                 self.modifier_keys_pressed.clear()
#                 raise KeyNotMapped("No such keybind: %r." % inp)
#         else:
#             self.modifier_keys_pressed.clear()
#             return command_input
# 
# def register_command(kls):
#     commands_mapping[kls.name] = kls
#     for a in kls.aliases:
#         commands_mapping[a] = kls
#     return kls
# 
# class Argument(ArgumentBase):
#     """
#     arguments are positional
#     """
#     pass


import pytest
from sen.tui.commands.base import Command, Option, Commander, register_command, Argument
# -*- coding: utf-8 -*-





@register_command
class MyCommand(Command):
    name = "test"
    description = "test desc"
    options_definitions = [
        Option("test-opt", "test-opt desc", aliases=["x"])
    ]
    aliases = ["mango"]

    def run(self):
        return 42


@register_command

# Path: sen/tui/commands/base.py
# class Command:
#     # command name, unique identifier, used also in prompt
#     name = ""
#     # message explaining what's about to happen
#     pre_info_message = ""
#     # message explaining what has happened
#     post_info_message = ""
#     # how long it takes to run the command - in which queue it should be executed
#     priority = None
#     # used in help message
#     description = ""
#     # define options
#     options_definitions = []
#     # define arguments
#     arguments_definitions = []
#     # command is available under these aliases
#     aliases = []
# 
#     def __init__(self, ui=None, docker_backend=None, docker_object=None, buffer=None, size=None):
#         """
# 
#         :param ui:
#         :param docker_backend:
#         :param docker_object:
#         :param buffer:
#         """
#         logger.debug(
#             "command %r initialized: ui=%r, docker_backend=%r, docker_object=%r, buffer=%r",
#             self.name, ui, docker_backend, docker_object, buffer)
#         self.ui = ui
#         self.docker_backend = docker_backend
#         self.docker_object = docker_object
#         self.buffer = buffer
#         self.size = size
#         self.argument_processor = ArgumentProcessor(self.options_definitions,
#                                                     self.arguments_definitions)
#         self.arguments = None
# 
#     def process_args(self, arguments):
#         """
# 
#         :param arguments: dict
#         :return:
#         """
#         given_arguments = self.argument_processor.process(arguments)
#         logger.info("given arguments = %s", given_arguments)
#         self.arguments = CommandArgumentsGetter(given_arguments)
# 
#     def run(self):
#         raise NotImplementedError()
# 
# class Option(ArgumentBase):
#     """
#     options alter behavior, are not positional
#     """
#     def __init__(self, name, description, action=true_action, aliases=None, default=None):
#         super().__init__(name, description, action=action, default=default)
#         self.aliases = aliases or []
# 
#     def __str__(self):
#         return "{} default={} action=\"{}\" aliases={}".format(
#             self.name, self.default, self.action, self.aliases
#         )
# 
#     def __unicode__(self):
#         return self.__str__()
# 
# class Commander:
#     """
#     Responsible for managing commands: it's up to workers to do the commands actually.
#     """
#     def __init__(self, ui, docker_backend):
#         self.ui = ui
#         self.docker_backend = docker_backend
#         self.modifier_keys_pressed = []
#         logger.debug("available commands: %s", commands_mapping)
# 
#     def get_command(self, command_input, docker_object=None, buffer=None, size=None):
#         """
#         return command instance which is the actual command to be executed
# 
#         :param command_input: str, command name and its args: "command arg arg2=val opt"
#         :param docker_object:
#         :param buffer:
#         :param size: tuple, so we can call urwid.keypress(size, ...)
#         :return: instance of Command
#         """
#         logger.debug("get command for command input %r", command_input)
# 
#         if not command_input:
#             # noop, don't do anything
#             return
# 
#         if command_input[0] in ["/"]:  # we could add here !, @, ...
#             command_name = command_input[0]
#             unparsed_command_args = shlex.split(command_input[1:])
#         else:
#             command_input_list = shlex.split(command_input)
#             command_name = command_input_list[0]
#             unparsed_command_args = command_input_list[1:]
# 
#         try:
#             CommandClass = commands_mapping[command_name]
#         except KeyError:
#             logger.info("no such command: %r", command_name)
#             raise NoSuchCommand("There is no such command: %s" % command_name)
#         else:
#             cmd = CommandClass(ui=self.ui, docker_backend=self.docker_backend,
#                                docker_object=docker_object, buffer=buffer, size=size)
#             cmd.process_args(unparsed_command_args)
#             return cmd
# 
#     def get_command_input_by_key(self, key):
#         logger.debug("get command input for key %r", key)
# 
#         modifier_keys = ["g"]  # FIXME: we should be able to figure this out from existing keybinds
# 
#         inp = "".join(self.modifier_keys_pressed) + key
# 
#         try:
#             command_input = self.ui.current_buffer.get_keybinds()[inp]
#         except KeyError:
#             if key in modifier_keys:
#                 # TODO: inform user maybe
#                 self.modifier_keys_pressed.append(key)
#                 logger.info("modifier keys pressed: %s", self.modifier_keys_pressed)
#                 return
#             else:
#                 logger.info("no such keybind: %r", inp)
#                 self.modifier_keys_pressed.clear()
#                 raise KeyNotMapped("No such keybind: %r." % inp)
#         else:
#             self.modifier_keys_pressed.clear()
#             return command_input
# 
# def register_command(kls):
#     commands_mapping[kls.name] = kls
#     for a in kls.aliases:
#         commands_mapping[a] = kls
#     return kls
# 
# class Argument(ArgumentBase):
#     """
#     arguments are positional
#     """
#     pass


# Path: tests/test_commands.py
import pytest
from sen.tui.commands.base import Command, Option, Commander, register_command, Argument

# -*- coding: utf-8 -*-





@register_command
class MyCommand(Command):
    name = "test"
    description = "test desc"
    options_definitions = [
        Option("test-opt", "test-opt desc", aliases=["x"])
    ]
    aliases = ["mango"]

    def run(self):
        return 42


@register_command

class MyCommand2(Command):