mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
new tests
This commit is contained in:
@@ -176,9 +176,9 @@ class App(BaseApp)
|
|||||||
#### \_\_init\_\_
|
#### \_\_init\_\_
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def __init__(prompt: str = '[italic dim bold]What do you want to do?\n',
|
def __init__(prompt: str = 'What do you want to do?',
|
||||||
initial_message: str = '\nArgenta\n',
|
initial_message: str = 'Argenta',
|
||||||
farewell_message: str = '\nSee you\n',
|
farewell_message: str = 'See you',
|
||||||
exit_command: Command = Command('Q', 'Exit command'),
|
exit_command: Command = Command('Q', 'Exit command'),
|
||||||
system_router_title: str | None = 'System points:',
|
system_router_title: str | None = 'System points:',
|
||||||
ignore_command_register: bool = True,
|
ignore_command_register: bool = True,
|
||||||
@@ -218,8 +218,7 @@ Configures and manages all aspects of the behavior and presentation of the user
|
|||||||
#### set\_description\_message\_pattern
|
#### set\_description\_message\_pattern
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def set_description_message_pattern(
|
def set_description_message_pattern(pattern: Callable[[str, str], str]) -> None
|
||||||
pattern: Callable[[str, str], str]) -> None
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Public. Sets the output pattern of the available commands
|
Public. Sets the output pattern of the available commands
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ work_router: Router = Router(title='Work points:')
|
|||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
|
|
||||||
@work_router.command(Command('get', 'Get Help', aliases=['help', 'Get_help']))
|
'''@work_router.command(Command('get', 'Get Help', aliases=['help', 'Get_help']))
|
||||||
def command_help():
|
def command_help():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@work_router.command(Command('run', 'Run All'))
|
@work_router.command(Command('run', 'Run All'))
|
||||||
def command_start_solving():
|
def command_start_solving():
|
||||||
pass
|
pass'''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
class NoRegisteredHandlersException(Exception):
|
|
||||||
"""
|
|
||||||
The router has no registered handlers
|
|
||||||
"""
|
|
||||||
def __init__(self, router_name) -> None:
|
|
||||||
self.router_name = router_name
|
|
||||||
def __str__(self):
|
|
||||||
return f"No Registered Handlers Found For '{self.router_name}'"
|
|
||||||
@@ -15,7 +15,6 @@ from argenta.command.exceptions import (UnprocessedInputFlagException,
|
|||||||
RepeatedInputFlagsException,
|
RepeatedInputFlagsException,
|
||||||
EmptyInputCommandException,
|
EmptyInputCommandException,
|
||||||
BaseInputCommandException)
|
BaseInputCommandException)
|
||||||
from argenta.app.exceptions import NoRegisteredHandlersException
|
|
||||||
from argenta.app.registered_routers.entity import RegisteredRouters
|
from argenta.app.registered_routers.entity import RegisteredRouters
|
||||||
|
|
||||||
|
|
||||||
@@ -184,11 +183,6 @@ class BaseApp:
|
|||||||
else:
|
else:
|
||||||
if input_command_trigger in self._all_registered_triggers_in_default_case:
|
if input_command_trigger in self._all_registered_triggers_in_default_case:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
with redirect_stdout(io.StringIO()) as f:
|
|
||||||
self._unknown_command_handler(command)
|
|
||||||
res: str = f.getvalue()
|
|
||||||
self._print_framed_text(res)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@@ -208,16 +202,6 @@ class BaseApp:
|
|||||||
self._empty_input_command_handler()
|
self._empty_input_command_handler()
|
||||||
|
|
||||||
|
|
||||||
def _validate_included_routers(self) -> None:
|
|
||||||
"""
|
|
||||||
Private. Validates included routers
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
for router in self._registered_routers:
|
|
||||||
if not router.get_command_handlers():
|
|
||||||
raise NoRegisteredHandlersException(router.get_name())
|
|
||||||
|
|
||||||
|
|
||||||
def _setup_system_router(self) -> None:
|
def _setup_system_router(self) -> None:
|
||||||
"""
|
"""
|
||||||
Private. Sets up system router
|
Private. Sets up system router
|
||||||
@@ -259,7 +243,6 @@ class BaseApp:
|
|||||||
"""
|
"""
|
||||||
self._setup_default_view()
|
self._setup_default_view()
|
||||||
self._setup_system_router()
|
self._setup_system_router()
|
||||||
self._validate_included_routers()
|
|
||||||
|
|
||||||
for router_entity in self._registered_routers:
|
for router_entity in self._registered_routers:
|
||||||
self._all_registered_triggers_in_default_case.extend(router_entity.get_triggers())
|
self._all_registered_triggers_in_default_case.extend(router_entity.get_triggers())
|
||||||
@@ -351,6 +334,10 @@ class App(BaseApp):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self._is_unknown_command(input_command):
|
if self._is_unknown_command(input_command):
|
||||||
|
with redirect_stdout(io.StringIO()) as f:
|
||||||
|
self._unknown_command_handler(input_command)
|
||||||
|
res: str = f.getvalue()
|
||||||
|
self._print_framed_text(res)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with redirect_stdout(io.StringIO()) as f:
|
with redirect_stdout(io.StringIO()) as f:
|
||||||
|
|||||||
@@ -49,14 +49,14 @@ class CommandHandlers:
|
|||||||
"""
|
"""
|
||||||
self.command_handlers = command_handlers if command_handlers else []
|
self.command_handlers = command_handlers if command_handlers else []
|
||||||
|
|
||||||
def get_command_handlers(self) -> list[CommandHandler]:
|
def get_handlers(self) -> list[CommandHandler]:
|
||||||
"""
|
"""
|
||||||
Private. Returns the list of CommandHandlers
|
Private. Returns the list of CommandHandlers
|
||||||
:return: the list of CommandHandlers as list[CommandHandler]
|
:return: the list of CommandHandlers as list[CommandHandler]
|
||||||
"""
|
"""
|
||||||
return self.command_handlers
|
return self.command_handlers
|
||||||
|
|
||||||
def add_command_handler(self, command_handler: CommandHandler) -> None:
|
def add_handler(self, command_handler: CommandHandler) -> None:
|
||||||
"""
|
"""
|
||||||
Private. Adds a CommandHandler to the list of CommandHandlers
|
Private. Adds a CommandHandler to the list of CommandHandlers
|
||||||
:param command_handler: CommandHandler to be added
|
:param command_handler: CommandHandler to be added
|
||||||
@@ -64,7 +64,7 @@ class CommandHandlers:
|
|||||||
"""
|
"""
|
||||||
self.command_handlers.append(command_handler)
|
self.command_handlers.append(command_handler)
|
||||||
|
|
||||||
def add_command_handlers(self, *command_handlers: CommandHandler) -> None:
|
def add_handlers(self, *command_handlers: CommandHandler) -> None:
|
||||||
"""
|
"""
|
||||||
Private. Extend a many CommandHandler to the list of CommandHandlers
|
Private. Extend a many CommandHandler to the list of CommandHandlers
|
||||||
:param command_handlers: many CommandHandler to be added
|
:param command_handlers: many CommandHandler to be added
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Router:
|
|||||||
|
|
||||||
def command_decorator(func):
|
def command_decorator(func):
|
||||||
Router._validate_func_args(command, func)
|
Router._validate_func_args(command, func)
|
||||||
self._command_handlers.add_command_handler(CommandHandler(func, command))
|
self._command_handlers.add_handler(CommandHandler(func, command))
|
||||||
|
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user