mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
steps
This commit is contained in:
@@ -9,6 +9,7 @@ class Orchestrator:
|
|||||||
"""
|
"""
|
||||||
An orchestrator and configurator that defines the behavior of an integrated system, one level higher than the App
|
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
|
:param arg_parser: Cmd argument parser and configurator at startup
|
||||||
|
:return: None
|
||||||
"""
|
"""
|
||||||
self.arg_parser: ArgParse | False = arg_parser
|
self.arg_parser: ArgParse | False = arg_parser
|
||||||
if arg_parser:
|
if arg_parser:
|
||||||
@@ -19,14 +20,14 @@ class Orchestrator:
|
|||||||
"""
|
"""
|
||||||
Starting the user input processing cycle
|
Starting the user input processing cycle
|
||||||
:param app: a running application
|
:param app: a running application
|
||||||
:return:
|
:return: None
|
||||||
"""
|
"""
|
||||||
app.run_polling()
|
app.run_polling()
|
||||||
|
|
||||||
def get_input_args(self) -> Namespace | None:
|
def get_input_args(self) -> Namespace | None:
|
||||||
"""
|
"""
|
||||||
Returns the arguments parsed
|
Returns the arguments parsed
|
||||||
:return:
|
:return: None
|
||||||
"""
|
"""
|
||||||
if self.arg_parser:
|
if self.arg_parser:
|
||||||
return self.arg_parser.entity.parse_args()
|
return self.arg_parser.entity.parse_args()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Callable, Any
|
from typing import Callable
|
||||||
from inspect import getfullargspec
|
from inspect import getfullargspec
|
||||||
|
|
||||||
from argenta.command import Command
|
from argenta.command import Command
|
||||||
@@ -16,6 +16,12 @@ class Router:
|
|||||||
def __init__(self,
|
def __init__(self,
|
||||||
title: str = None,
|
title: str = None,
|
||||||
name: str = 'Default'):
|
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._title = title
|
||||||
self._name = name
|
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 ''}")
|
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)
|
self._validate_command(command)
|
||||||
|
|
||||||
def command_decorator(func):
|
def command_decorator(func):
|
||||||
@@ -38,7 +49,12 @@ class Router:
|
|||||||
return command_decorator
|
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
|
processed_args = getfullargspec(func).args
|
||||||
if len(processed_args) != 1:
|
if len(processed_args) != 1:
|
||||||
raise IncorrectNumberOfHandlerArgsException()
|
raise IncorrectNumberOfHandlerArgsException()
|
||||||
@@ -46,7 +62,12 @@ class Router:
|
|||||||
self._not_valid_flag_handler = func
|
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_name: str = input_command.get_trigger()
|
||||||
input_command_flags: InputFlags = input_command.get_input_flags()
|
input_command_flags: InputFlags = input_command.get_input_flags()
|
||||||
|
|
||||||
@@ -59,7 +80,13 @@ class Router:
|
|||||||
self._validate_input_command(input_command_flags, command_handler)
|
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()
|
handle_command = command_handler.get_handled_command()
|
||||||
if handle_command.get_registered_flags().get_flags():
|
if handle_command.get_registered_flags().get_flags():
|
||||||
if input_command_flags.get_flags():
|
if input_command_flags.get_flags():
|
||||||
|
|||||||
@@ -1,23 +1,38 @@
|
|||||||
class RepeatedFlagNameException(Exception):
|
class RepeatedFlagNameException(Exception):
|
||||||
|
"""
|
||||||
|
Private. Raised when a repeated flag name is registered
|
||||||
|
"""
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Repeated registered_flag name in register command"
|
return "Repeated registered_flag name in register command"
|
||||||
|
|
||||||
|
|
||||||
class TooManyTransferredArgsException(Exception):
|
class TooManyTransferredArgsException(Exception):
|
||||||
|
"""
|
||||||
|
Private. Raised when too many arguments are passed
|
||||||
|
"""
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Too many transferred arguments"
|
return "Too many transferred arguments"
|
||||||
|
|
||||||
|
|
||||||
class RequiredArgumentNotPassedException(Exception):
|
class RequiredArgumentNotPassedException(Exception):
|
||||||
|
"""
|
||||||
|
Private. Raised when a required argument is not passed
|
||||||
|
"""
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Required argument not passed"
|
return "Required argument not passed"
|
||||||
|
|
||||||
|
|
||||||
class IncorrectNumberOfHandlerArgsException(Exception):
|
class IncorrectNumberOfHandlerArgsException(Exception):
|
||||||
|
"""
|
||||||
|
Private. Raised when incorrect number of arguments are passed
|
||||||
|
"""
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Handler has incorrect number of arguments"
|
return "Handler has incorrect number of arguments"
|
||||||
|
|
||||||
|
|
||||||
class TriggerCannotContainSpacesException(Exception):
|
class TriggerCannotContainSpacesException(Exception):
|
||||||
|
"""
|
||||||
|
Private. Raised when there is a space in the trigger being registered
|
||||||
|
"""
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Command trigger cannot contain spaces"
|
return "Command trigger cannot contain spaces"
|
||||||
|
|||||||
Reference in New Issue
Block a user