mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
v0.3.2
This commit is contained in:
+30
-6
@@ -4,10 +4,12 @@ from inspect import getfullargspec
|
||||
from ..command.entity import Command
|
||||
from ..router.entity import Router
|
||||
from ..command.input_comand.entity import InputCommand
|
||||
from ..command.input_comand.exceptions import (IncorrectInputFlagException,
|
||||
from ..command.input_comand.exceptions import (UnprocessedInputFlagException,
|
||||
InvalidInputFlagsHandlerHasBeenAlreadyCreatedException,
|
||||
IncorrectNumberArgsHandlerException,
|
||||
UnknownCommandHandlerHasBeenAlreadyCreatedException)
|
||||
IncorrectNumberOfHandlerArgsException,
|
||||
UnknownCommandHandlerHasBeenAlreadyCreatedException,
|
||||
RepeatedInputFlagsException,
|
||||
RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException)
|
||||
from .exceptions import (InvalidRouterInstanceException,
|
||||
InvalidDescriptionMessagePatternException,
|
||||
NoRegisteredRoutersException,
|
||||
@@ -46,6 +48,7 @@ class App:
|
||||
|
||||
self._routers: list[Router] = []
|
||||
self._invalid_input_flags_handler: Callable[[str], None] | None = None
|
||||
self._repeated_input_flags_handler: Callable[[str], None] | None = None
|
||||
self._unknown_command_handler: Callable[[Command], None] | None = None
|
||||
self._registered_router_entities: list[dict[str, str | list[dict[str, Callable[[], None] | Command]] | Router]] = []
|
||||
self._app_main_router: Router | None = None
|
||||
@@ -72,7 +75,7 @@ class App:
|
||||
|
||||
try:
|
||||
input_command: InputCommand = InputCommand.parse(raw_command=raw_command)
|
||||
except IncorrectInputFlagException:
|
||||
except UnprocessedInputFlagException:
|
||||
self.print_func(self.line_separate)
|
||||
if self._invalid_input_flags_handler:
|
||||
self._invalid_input_flags_handler(raw_command)
|
||||
@@ -82,6 +85,16 @@ class App:
|
||||
if not self.repeat_command_groups:
|
||||
self.print_func(self.prompt)
|
||||
continue
|
||||
except RepeatedInputFlagsException:
|
||||
self.print_func(self.line_separate)
|
||||
if self._repeated_input_flags_handler:
|
||||
self._repeated_input_flags_handler(raw_command)
|
||||
else:
|
||||
self.print_func(f'Repeated input flags: "{raw_command}"')
|
||||
self.print_func(self.line_separate)
|
||||
if not self.repeat_command_groups:
|
||||
self.print_func(self.prompt)
|
||||
continue
|
||||
|
||||
self._checking_command_for_exit_command(input_command.get_string_entity())
|
||||
self.print_func(self.line_separate)
|
||||
@@ -125,18 +138,29 @@ class App:
|
||||
else:
|
||||
args = getfullargspec(handler).args
|
||||
if len(args) != 1:
|
||||
raise IncorrectNumberArgsHandlerException()
|
||||
raise IncorrectNumberOfHandlerArgsException()
|
||||
else:
|
||||
self._invalid_input_flags_handler = handler
|
||||
|
||||
|
||||
def set_repeated_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
||||
if self._repeated_input_flags_handler:
|
||||
raise RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException()
|
||||
else:
|
||||
args = getfullargspec(handler).args
|
||||
if len(args) != 1:
|
||||
raise IncorrectNumberOfHandlerArgsException()
|
||||
else:
|
||||
self._repeated_input_flags_handler = handler
|
||||
|
||||
|
||||
def set_unknown_command_handler(self, handler: Callable[[str], None]) -> None:
|
||||
if self._unknown_command_handler:
|
||||
raise UnknownCommandHandlerHasBeenAlreadyCreatedException()
|
||||
else:
|
||||
args = getfullargspec(handler).args
|
||||
if len(args) != 1:
|
||||
raise IncorrectNumberArgsHandlerException()
|
||||
raise IncorrectNumberOfHandlerArgsException()
|
||||
else:
|
||||
self._unknown_command_handler = handler
|
||||
|
||||
|
||||
Reference in New Issue
Block a user