mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
0.3.1
This commit is contained in:
@@ -1,3 +1,2 @@
|
||||
from .entity import Router
|
||||
from .exceptions import (UnknownCommandHandlerHasAlreadyBeenCreatedException,
|
||||
InvalidDescriptionInstanceException)
|
||||
from .exceptions import InvalidDescriptionInstanceException
|
||||
@@ -4,8 +4,7 @@ from ..command.entity import Command
|
||||
from ..command.input_comand.entity import InputCommand
|
||||
from ..command.input_comand.exceptions import InvalidInputFlagException
|
||||
from ..command.params.flag.flags_group.entity import FlagsGroup
|
||||
from ..router.exceptions import (UnknownCommandHandlerHasAlreadyBeenCreatedException,
|
||||
RepeatedCommandException, RepeatedFlagNameException,
|
||||
from ..router.exceptions import (RepeatedCommandException, RepeatedFlagNameException,
|
||||
CurrentCommandDoesNotProcessFlagsException,
|
||||
TooManyTransferredArgsException,
|
||||
RequiredArgumentNotPassedException)
|
||||
@@ -20,7 +19,6 @@ class Router:
|
||||
self.name = name
|
||||
|
||||
self._command_entities: list[dict[str, Callable[[], None] | Command]] = []
|
||||
self._is_main_router: bool = False
|
||||
self._ignore_command_register: bool = False
|
||||
|
||||
self._unknown_command_handler: Callable[[str], None] | None = None
|
||||
@@ -42,17 +40,6 @@ class Router:
|
||||
return command_decorator
|
||||
|
||||
|
||||
def unknown_command(self, func):
|
||||
if self._unknown_command_handler is not None:
|
||||
raise UnknownCommandHandlerHasAlreadyBeenCreatedException()
|
||||
|
||||
self._unknown_command_handler: Callable = func
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
|
||||
def input_command_handler(self, input_command: InputCommand):
|
||||
input_command_name: str = input_command.get_string_entity()
|
||||
for command_entity in self._command_entities:
|
||||
@@ -73,14 +60,6 @@ class Router:
|
||||
return command_entity['handler_func']()
|
||||
|
||||
|
||||
def get_unknown_command_func(self):
|
||||
return self._unknown_command_handler
|
||||
|
||||
|
||||
def unknown_command_handler(self, unknown_command):
|
||||
self._unknown_command_handler(unknown_command)
|
||||
|
||||
|
||||
def _validate_command(self, command: Command):
|
||||
command_name: str = command.get_string_entity()
|
||||
if command_name in self.get_all_commands():
|
||||
@@ -109,13 +88,6 @@ class Router:
|
||||
raise TooManyTransferredArgsException()
|
||||
|
||||
|
||||
|
||||
def set_router_as_main(self):
|
||||
if self.name == 'subordinate':
|
||||
self.name = 'main'
|
||||
self._is_main_router = True
|
||||
|
||||
|
||||
def set_ignore_command_register(self, ignore_command_register: bool):
|
||||
self._ignore_command_register = ignore_command_register
|
||||
|
||||
@@ -139,8 +111,7 @@ class Router:
|
||||
'ignore_command_register': self._ignore_command_register,
|
||||
'attributes': {
|
||||
'command_entities': self._command_entities,
|
||||
'unknown_command_func': self._unknown_command_handler,
|
||||
'is_main_router': self._is_main_router
|
||||
'unknown_command_func': self._unknown_command_handler
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,11 +3,6 @@ class InvalidDescriptionInstanceException(Exception):
|
||||
return "Invalid Description Instance"
|
||||
|
||||
|
||||
class UnknownCommandHandlerHasAlreadyBeenCreatedException(Exception):
|
||||
def __str__(self):
|
||||
return "Only one unknown command handler can be declared"
|
||||
|
||||
|
||||
class RepeatedCommandException(Exception):
|
||||
def __str__(self):
|
||||
return "Commands in handler cannot be repeated"
|
||||
|
||||
Reference in New Issue
Block a user