From 051ec6df289175fd59bd3b4265a4a3e63f7888d9 Mon Sep 17 00:00:00 2001 From: kolo Date: Sun, 20 Apr 2025 23:58:15 +0300 Subject: [PATCH] steps --- argenta/orchestrator/entity.py | 5 +++-- argenta/router/entity.py | 37 +++++++++++++++++++++++++++++----- argenta/router/exceptions.py | 15 ++++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/argenta/orchestrator/entity.py b/argenta/orchestrator/entity.py index ec47c5b..6c11857 100644 --- a/argenta/orchestrator/entity.py +++ b/argenta/orchestrator/entity.py @@ -9,6 +9,7 @@ class Orchestrator: """ An orchestrator and configurator that defines the behavior of an integrated system, one level higher than the App :param arg_parser: Cmd argument parser and configurator at startup + :return: None """ self.arg_parser: ArgParse | False = arg_parser if arg_parser: @@ -19,14 +20,14 @@ class Orchestrator: """ Starting the user input processing cycle :param app: a running application - :return: + :return: None """ app.run_polling() def get_input_args(self) -> Namespace | None: """ Returns the arguments parsed - :return: + :return: None """ if self.arg_parser: return self.arg_parser.entity.parse_args() diff --git a/argenta/router/entity.py b/argenta/router/entity.py index 0453784..dc8fbdb 100644 --- a/argenta/router/entity.py +++ b/argenta/router/entity.py @@ -1,4 +1,4 @@ -from typing import Callable, Any +from typing import Callable from inspect import getfullargspec from argenta.command import Command @@ -16,6 +16,12 @@ class Router: def __init__(self, title: str = None, name: str = 'Default'): + """ + Public. Directly configures and manages handlers + :param title: the title of the router + :param name: the name of the router + :return: None + """ self._title = title self._name = name @@ -24,7 +30,12 @@ class Router: self._not_valid_flag_handler: Callable[[Flag], None] = lambda flag: print(f"Undefined or incorrect input flag: {flag.get_string_entity()}{(' '+flag.get_value()) if flag.get_value() else ''}") - def command(self, command: Command) -> Callable[[Any], Any]: + def command(self, command: Command) -> Callable: + """ + Public. Registers handler + :param command: Registered command + :return: decorated handler as Callable[[Any], Any] + """ self._validate_command(command) def command_decorator(func): @@ -38,7 +49,12 @@ class Router: return command_decorator - def set_invalid_input_flag_handler(self, func): + def set_invalid_input_flag_handler(self, func) -> None: + """ + Public. Registers handler for invalid input flag + :param func: registered handler + :return: None + """ processed_args = getfullargspec(func).args if len(processed_args) != 1: raise IncorrectNumberOfHandlerArgsException() @@ -46,7 +62,12 @@ class Router: self._not_valid_flag_handler = func - def input_command_handler(self, input_command: InputCommand): + def input_command_handler(self, input_command: InputCommand) -> None: + """ + Private. One handler for all input commands + :param input_command: input command as InputCommand + :return: None + """ input_command_name: str = input_command.get_trigger() input_command_flags: InputFlags = input_command.get_input_flags() @@ -59,7 +80,13 @@ class Router: self._validate_input_command(input_command_flags, command_handler) - def _validate_input_command(self, input_command_flags: InputFlags, command_handler: CommandHandler): + def _validate_input_command(self, input_command_flags: InputFlags, command_handler: CommandHandler) -> None: + """ + Private. Validates flags of input command + :param input_command_flags: input command flags as InputFlags + :param command_handler: command handler for input command as CommandHandler + :return: None + """ handle_command = command_handler.get_handled_command() if handle_command.get_registered_flags().get_flags(): if input_command_flags.get_flags(): diff --git a/argenta/router/exceptions.py b/argenta/router/exceptions.py index 61bdcad..ca3ed1f 100644 --- a/argenta/router/exceptions.py +++ b/argenta/router/exceptions.py @@ -1,23 +1,38 @@ class RepeatedFlagNameException(Exception): + """ + Private. Raised when a repeated flag name is registered + """ def __str__(self): return "Repeated registered_flag name in register command" class TooManyTransferredArgsException(Exception): + """ + Private. Raised when too many arguments are passed + """ def __str__(self): return "Too many transferred arguments" class RequiredArgumentNotPassedException(Exception): + """ + Private. Raised when a required argument is not passed + """ def __str__(self): return "Required argument not passed" class IncorrectNumberOfHandlerArgsException(Exception): + """ + Private. Raised when incorrect number of arguments are passed + """ def __str__(self): return "Handler has incorrect number of arguments" class TriggerCannotContainSpacesException(Exception): + """ + Private. Raised when there is a space in the trigger being registered + """ def __str__(self): return "Command trigger cannot contain spaces"