work on Response model

This commit is contained in:
2025-04-30 00:08:49 +03:00
parent 315508a36e
commit 1159dda16e
3 changed files with 13 additions and 4 deletions
+4 -1
View File
@@ -3,6 +3,7 @@ from rich.console import Console
from argenta.command import Command
from argenta.command.flag.defaults import PredefinedFlags
from argenta.command.flag.models import Flag
from argenta.command.flags.models import Flags
from argenta.response import Response
from argenta.router import Router
@@ -12,7 +13,8 @@ work_router: Router = Router(title='Work points:')
console = Console()
@work_router.command(Command('get', 'Get Help', aliases=['help', 'Get_help'], flags=PredefinedFlags.PORT))
@work_router.command(Command('get', 'Get Help', aliases=['help', 'Get_help'], flags=Flags(PredefinedFlags.PORT,
PredefinedFlags.HOST)))
def command_help(response: Response):
print(response.status)
print(response.undefined_flags.get_flags())
@@ -23,6 +25,7 @@ def command_help(response: Response):
@work_router.command(Command('run', 'Run All'))
def command_start_solving(response: Response):
print(response.status)
print('srsfbd')
print(response.undefined_flags.get_flags())
print(response.valid_flags.get_flags())
print(response.invalid_value_flags.get_flags())
+7
View File
@@ -7,6 +7,13 @@ class Response:
valid_flags: ValidInputFlags = ValidInputFlags(),
undefined_flags: UndefinedInputFlags = UndefinedInputFlags(),
invalid_value_flags: InvalidValueInputFlags = InvalidValueInputFlags()):
"""
Public. The entity of the user input sent to the handler
:param status: the status of the response
:param valid_flags: valid input flags
:param undefined_flags: undefined input flags
:param invalid_value_flags: input flags with invalid values
"""
self.status = status
self.valid_flags = valid_flags
self.undefined_flags = undefined_flags
+2 -3
View File
@@ -34,7 +34,7 @@ class Router:
self._validate_command(command)
def command_decorator(func):
Router._validate_func_args(command, func)
Router._validate_func_args(func)
self._command_handlers.add_handler(CommandHandler(func, command))
def wrapper(*args, **kwargs):
@@ -134,10 +134,9 @@ class Router:
@staticmethod
def _validate_func_args(command: Command, func: Callable) -> None:
def _validate_func_args(func: Callable) -> None:
"""
Private. Validates the arguments of the handler
:param command: registered command in handler
:param func: entity of the handler func
:return: None if func is valid else raise exception
"""