argenta 0.5.0b0__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- argenta/app/autocompleter/entity.py +57 -13
- argenta/app/defaults.py +7 -4
- argenta/app/dividing_line/models.py +55 -13
- argenta/app/models.py +376 -178
- argenta/app/registered_routers/entity.py +20 -7
- argenta/command/__init__.py +1 -1
- argenta/command/exceptions.py +22 -3
- argenta/command/flag/__init__.py +2 -2
- argenta/command/flag/defaults.py +21 -11
- argenta/command/flag/models.py +73 -92
- argenta/command/flags/__init__.py +16 -0
- argenta/command/flags/models.py +90 -0
- argenta/command/models.py +124 -39
- argenta/orchestrator/__init__.py +4 -0
- argenta/orchestrator/argparser/__init__.py +4 -0
- argenta/orchestrator/argparser/arguments/__init__.py +8 -0
- argenta/orchestrator/argparser/arguments/models.py +56 -0
- argenta/orchestrator/argparser/entity.py +59 -0
- argenta/orchestrator/entity.py +35 -0
- argenta/response/__init__.py +5 -0
- argenta/response/entity.py +29 -0
- argenta/response/status.py +8 -0
- argenta/router/__init__.py +1 -1
- argenta/router/command_handler/entity.py +57 -11
- argenta/router/defaults.py +1 -2
- argenta/router/entity.py +181 -92
- argenta/router/exceptions.py +17 -6
- argenta-1.0.0.dist-info/METADATA +70 -0
- argenta-1.0.0.dist-info/RECORD +37 -0
- {argenta-0.5.0b0.dist-info → argenta-1.0.0.dist-info}/WHEEL +1 -1
- argenta/app/exceptions.py +0 -15
- argenta/router/command_handlers/__init__.py +0 -0
- argenta/router/command_handlers/entity.py +0 -21
- argenta-0.5.0b0.dist-info/METADATA +0 -603
- argenta-0.5.0b0.dist-info/RECORD +0 -29
- {argenta-0.5.0b0.dist-info → argenta-1.0.0.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from typing import Literal
|
3
|
+
|
4
|
+
|
5
|
+
class BaseArgument(ABC):
|
6
|
+
"""
|
7
|
+
Private. Base class for all arguments
|
8
|
+
"""
|
9
|
+
|
10
|
+
@abstractmethod
|
11
|
+
def get_string_entity(self) -> str:
|
12
|
+
"""
|
13
|
+
Public. Returns the string representation of the argument
|
14
|
+
:return: the string representation as a str
|
15
|
+
"""
|
16
|
+
pass
|
17
|
+
|
18
|
+
|
19
|
+
class PositionalArgument(BaseArgument):
|
20
|
+
def __init__(self, name: str):
|
21
|
+
"""
|
22
|
+
Public. Required argument at startup
|
23
|
+
:param name: name of the argument, must not start with minus (-)
|
24
|
+
"""
|
25
|
+
self.name = name
|
26
|
+
|
27
|
+
def get_string_entity(self):
|
28
|
+
return self.name
|
29
|
+
|
30
|
+
|
31
|
+
class OptionalArgument(BaseArgument):
|
32
|
+
def __init__(self, name: str, prefix: Literal["-", "--", "---"] = "--"):
|
33
|
+
"""
|
34
|
+
Public. Optional argument, must have the value
|
35
|
+
:param name: name of the argument
|
36
|
+
:param prefix: prefix of the argument
|
37
|
+
"""
|
38
|
+
self.name = name
|
39
|
+
self.prefix = prefix
|
40
|
+
|
41
|
+
def get_string_entity(self):
|
42
|
+
return self.prefix + self.name
|
43
|
+
|
44
|
+
|
45
|
+
class BooleanArgument(BaseArgument):
|
46
|
+
def __init__(self, name: str, prefix: Literal["-", "--", "---"] = "--"):
|
47
|
+
"""
|
48
|
+
Public. Boolean argument, does not require a value
|
49
|
+
:param name: name of the argument
|
50
|
+
:param prefix: prefix of the argument
|
51
|
+
"""
|
52
|
+
self.name = name
|
53
|
+
self.prefix = prefix
|
54
|
+
|
55
|
+
def get_string_entity(self):
|
56
|
+
return self.prefix + self.name
|
@@ -0,0 +1,59 @@
|
|
1
|
+
from argparse import ArgumentParser
|
2
|
+
|
3
|
+
from argenta.orchestrator.argparser.arguments.models import (
|
4
|
+
BooleanArgument,
|
5
|
+
OptionalArgument,
|
6
|
+
PositionalArgument,
|
7
|
+
)
|
8
|
+
|
9
|
+
|
10
|
+
class ArgParser:
|
11
|
+
def __init__(
|
12
|
+
self,
|
13
|
+
processed_args: list[PositionalArgument | OptionalArgument | BooleanArgument],
|
14
|
+
name: str = "Argenta",
|
15
|
+
description: str = "Argenta available arguments",
|
16
|
+
epilog: str = "github.com/koloideal/Argenta | made by kolo",
|
17
|
+
) -> None:
|
18
|
+
"""
|
19
|
+
Public. Cmd argument parser and configurator at startup
|
20
|
+
:param name: the name of the ArgParse instance
|
21
|
+
:param description: the description of the ArgParse instance
|
22
|
+
:param epilog: the epilog of the ArgParse instance
|
23
|
+
:param processed_args: registered and processed arguments
|
24
|
+
"""
|
25
|
+
self.name = name
|
26
|
+
self.description = description
|
27
|
+
self.epilog = epilog
|
28
|
+
|
29
|
+
self.entity: ArgumentParser = ArgumentParser(
|
30
|
+
prog=name, description=description, epilog=epilog
|
31
|
+
)
|
32
|
+
self.args: (
|
33
|
+
list[PositionalArgument | OptionalArgument | BooleanArgument] | None
|
34
|
+
) = processed_args
|
35
|
+
|
36
|
+
def set_args(
|
37
|
+
self, *args: PositionalArgument | OptionalArgument | BooleanArgument
|
38
|
+
) -> None:
|
39
|
+
"""
|
40
|
+
Public. Sets the arguments to be processed
|
41
|
+
:param args: processed arguments
|
42
|
+
:return: None
|
43
|
+
"""
|
44
|
+
self.args.extend(args)
|
45
|
+
|
46
|
+
def register_args(self) -> None:
|
47
|
+
"""
|
48
|
+
Private. Registers initialized command line arguments
|
49
|
+
:return: None
|
50
|
+
"""
|
51
|
+
if not self.args:
|
52
|
+
return
|
53
|
+
for arg in self.args:
|
54
|
+
if type(arg) is PositionalArgument:
|
55
|
+
self.entity.add_argument(arg.get_string_entity())
|
56
|
+
elif type(arg) is OptionalArgument:
|
57
|
+
self.entity.add_argument(arg.get_string_entity())
|
58
|
+
elif type(arg) is BooleanArgument:
|
59
|
+
self.entity.add_argument(arg.get_string_entity(), action="store_true")
|
@@ -0,0 +1,35 @@
|
|
1
|
+
from argparse import Namespace
|
2
|
+
|
3
|
+
from argenta.app import App
|
4
|
+
from argenta.orchestrator.argparser import ArgParser
|
5
|
+
|
6
|
+
|
7
|
+
class Orchestrator:
|
8
|
+
def __init__(self, arg_parser: ArgParser = False):
|
9
|
+
"""
|
10
|
+
Public. An orchestrator and configurator that defines the behavior of an integrated system, one level higher than the App
|
11
|
+
:param arg_parser: Cmd argument parser and configurator at startup
|
12
|
+
:return: None
|
13
|
+
"""
|
14
|
+
self.arg_parser: ArgParser | False = arg_parser
|
15
|
+
if arg_parser:
|
16
|
+
self.arg_parser.register_args()
|
17
|
+
|
18
|
+
@staticmethod
|
19
|
+
def start_polling(app: App) -> None:
|
20
|
+
"""
|
21
|
+
Public. Starting the user input processing cycle
|
22
|
+
:param app: a running application
|
23
|
+
:return: None
|
24
|
+
"""
|
25
|
+
app.run_polling()
|
26
|
+
|
27
|
+
def get_input_args(self) -> Namespace | None:
|
28
|
+
"""
|
29
|
+
Public. Returns the arguments parsed
|
30
|
+
:return: None
|
31
|
+
"""
|
32
|
+
if self.arg_parser:
|
33
|
+
return self.arg_parser.entity.parse_args()
|
34
|
+
else:
|
35
|
+
return None
|
@@ -0,0 +1,29 @@
|
|
1
|
+
from argenta.response.status import Status
|
2
|
+
from argenta.command.flags import (
|
3
|
+
ValidInputFlags,
|
4
|
+
UndefinedInputFlags,
|
5
|
+
InvalidValueInputFlags,
|
6
|
+
)
|
7
|
+
|
8
|
+
|
9
|
+
class Response:
|
10
|
+
__slots__ = ("status", "valid_flags", "undefined_flags", "invalid_value_flags")
|
11
|
+
|
12
|
+
def __init__(
|
13
|
+
self,
|
14
|
+
status: Status = None,
|
15
|
+
valid_flags: ValidInputFlags = ValidInputFlags(),
|
16
|
+
undefined_flags: UndefinedInputFlags = UndefinedInputFlags(),
|
17
|
+
invalid_value_flags: InvalidValueInputFlags = InvalidValueInputFlags(),
|
18
|
+
):
|
19
|
+
"""
|
20
|
+
Public. The entity of the user input sent to the handler
|
21
|
+
:param status: the status of the response
|
22
|
+
:param valid_flags: valid input flags
|
23
|
+
:param undefined_flags: undefined input flags
|
24
|
+
:param invalid_value_flags: input flags with invalid values
|
25
|
+
"""
|
26
|
+
self.status = status
|
27
|
+
self.valid_flags = valid_flags
|
28
|
+
self.undefined_flags = undefined_flags
|
29
|
+
self.invalid_value_flags = invalid_value_flags
|
argenta/router/__init__.py
CHANGED
@@ -1,21 +1,67 @@
|
|
1
|
-
from typing import Callable
|
1
|
+
from typing import Callable, Iterator
|
2
|
+
|
2
3
|
from argenta.command import Command
|
3
|
-
from argenta.
|
4
|
+
from argenta.response import Response
|
4
5
|
|
5
6
|
|
6
7
|
class CommandHandler:
|
7
|
-
def __init__(self, handler: Callable[[], None]
|
8
|
+
def __init__(self, handler: Callable[[Response], None], handled_command: Command):
|
9
|
+
"""
|
10
|
+
Private. Entity of the model linking the handler and the command being processed
|
11
|
+
:param handler: the handler being called
|
12
|
+
:param handled_command: the command being processed
|
13
|
+
"""
|
8
14
|
self._handler = handler
|
9
15
|
self._handled_command = handled_command
|
10
16
|
|
11
|
-
def handling(self,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
def handling(self, response: Response) -> None:
|
18
|
+
"""
|
19
|
+
Private. Direct processing of an input command
|
20
|
+
:param response: the entity of response: various groups of flags and status of response
|
21
|
+
:return: None
|
22
|
+
"""
|
23
|
+
self._handler(response)
|
16
24
|
|
17
|
-
def get_handler(self):
|
25
|
+
def get_handler(self) -> Callable[[Response], None]:
|
26
|
+
"""
|
27
|
+
Private. Returns the handler being called
|
28
|
+
:return: the handler being called as Callable[[Response], None]
|
29
|
+
"""
|
18
30
|
return self._handler
|
19
31
|
|
20
|
-
def get_handled_command(self):
|
21
|
-
|
32
|
+
def get_handled_command(self) -> Command:
|
33
|
+
"""
|
34
|
+
Private. Returns the command being processed
|
35
|
+
:return: the command being processed as Command
|
36
|
+
"""
|
37
|
+
return self._handled_command
|
38
|
+
|
39
|
+
|
40
|
+
class CommandHandlers:
|
41
|
+
def __init__(self, command_handlers: list[CommandHandler] = None):
|
42
|
+
"""
|
43
|
+
Private. The model that unites all CommandHandler of the routers
|
44
|
+
:param command_handlers: list of CommandHandlers for register
|
45
|
+
"""
|
46
|
+
self.command_handlers = command_handlers if command_handlers else []
|
47
|
+
|
48
|
+
def get_handlers(self) -> list[CommandHandler]:
|
49
|
+
"""
|
50
|
+
Private. Returns the list of CommandHandlers
|
51
|
+
:return: the list of CommandHandlers as list[CommandHandler]
|
52
|
+
"""
|
53
|
+
return self.command_handlers
|
54
|
+
|
55
|
+
def add_handler(self, command_handler: CommandHandler) -> None:
|
56
|
+
"""
|
57
|
+
Private. Adds a CommandHandler to the list of CommandHandlers
|
58
|
+
:param command_handler: CommandHandler to be added
|
59
|
+
:return: None
|
60
|
+
"""
|
61
|
+
self.command_handlers.append(command_handler)
|
62
|
+
|
63
|
+
def __iter__(self) -> Iterator[CommandHandler]:
|
64
|
+
return iter(self.command_handlers)
|
65
|
+
|
66
|
+
def __next__(self) -> CommandHandler:
|
67
|
+
return next(iter(self.command_handlers))
|
argenta/router/defaults.py
CHANGED
argenta/router/entity.py
CHANGED
@@ -1,149 +1,238 @@
|
|
1
|
-
from typing import Callable,
|
2
|
-
from inspect import getfullargspec
|
1
|
+
from typing import Callable, Literal, Type
|
2
|
+
from inspect import getfullargspec, get_annotations, getsourcefile, getsourcelines
|
3
|
+
from rich.console import Console
|
3
4
|
|
4
5
|
from argenta.command import Command
|
5
6
|
from argenta.command.models import InputCommand
|
6
|
-
from argenta.
|
7
|
-
from argenta.router.command_handler.entity import CommandHandler
|
8
|
-
from argenta.command.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
from argenta.response import Response, Status
|
8
|
+
from argenta.router.command_handler.entity import CommandHandlers, CommandHandler
|
9
|
+
from argenta.command.flags.models import (
|
10
|
+
Flags,
|
11
|
+
InputFlags,
|
12
|
+
UndefinedInputFlags,
|
13
|
+
ValidInputFlags,
|
14
|
+
InvalidValueInputFlags,
|
15
|
+
)
|
16
|
+
from argenta.router.exceptions import (
|
17
|
+
RepeatedFlagNameException,
|
18
|
+
TooManyTransferredArgsException,
|
19
|
+
RequiredArgumentNotPassedException,
|
20
|
+
TriggerContainSpacesException,
|
21
|
+
)
|
14
22
|
|
15
23
|
|
16
24
|
class Router:
|
17
|
-
def __init__(self,
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
25
|
+
def __init__(self, title: str | None = "Awesome title"):
|
26
|
+
"""
|
27
|
+
Public. Directly configures and manages handlers
|
28
|
+
:param title: the title of the router, displayed when displaying the available commands
|
29
|
+
:return: None
|
30
|
+
"""
|
31
|
+
self.title = title
|
22
32
|
|
23
33
|
self._command_handlers: CommandHandlers = CommandHandlers()
|
24
34
|
self._ignore_command_register: bool = False
|
25
|
-
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 ''}")
|
26
35
|
|
27
|
-
|
28
|
-
|
36
|
+
def command(self, command: Command | str) -> Callable:
|
37
|
+
"""
|
38
|
+
Public. Registers handler
|
39
|
+
:param command: Registered command
|
40
|
+
:return: decorated handler as Callable
|
41
|
+
"""
|
29
42
|
self._validate_command(command)
|
43
|
+
if isinstance(command, str):
|
44
|
+
command = Command(command)
|
30
45
|
|
31
46
|
def command_decorator(func):
|
32
|
-
Router._validate_func_args(
|
33
|
-
self._command_handlers.
|
47
|
+
Router._validate_func_args(func)
|
48
|
+
self._command_handlers.add_handler(CommandHandler(func, command))
|
34
49
|
|
35
50
|
def wrapper(*args, **kwargs):
|
36
51
|
return func(*args, **kwargs)
|
52
|
+
|
37
53
|
return wrapper
|
38
54
|
|
39
55
|
return command_decorator
|
40
56
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
self._not_valid_flag_handler = func
|
48
|
-
|
49
|
-
|
50
|
-
def input_command_handler(self, input_command: InputCommand):
|
57
|
+
def finds_appropriate_handler(self, input_command: InputCommand) -> None:
|
58
|
+
"""
|
59
|
+
Private. Finds the appropriate handler for given input command and passes control to it
|
60
|
+
:param input_command: input command as InputCommand
|
61
|
+
:return: None
|
62
|
+
"""
|
51
63
|
input_command_name: str = input_command.get_trigger()
|
52
64
|
input_command_flags: InputFlags = input_command.get_input_flags()
|
53
65
|
|
54
66
|
for command_handler in self._command_handlers:
|
55
67
|
handle_command = command_handler.get_handled_command()
|
56
68
|
if input_command_name.lower() == handle_command.get_trigger().lower():
|
57
|
-
self.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
69
|
+
self.process_input_command(input_command_flags, command_handler)
|
70
|
+
if input_command_name.lower() in handle_command.get_aliases():
|
71
|
+
self.process_input_command(input_command_flags, command_handler)
|
72
|
+
|
73
|
+
def process_input_command(
|
74
|
+
self, input_command_flags: InputFlags, command_handler: CommandHandler
|
75
|
+
) -> None:
|
76
|
+
"""
|
77
|
+
Private. Processes input command with the appropriate handler
|
78
|
+
:param input_command_flags: input command flags as InputFlags
|
79
|
+
:param command_handler: command handler for input command as CommandHandler
|
80
|
+
:return: None
|
81
|
+
"""
|
64
82
|
handle_command = command_handler.get_handled_command()
|
83
|
+
response: Response = Response()
|
65
84
|
if handle_command.get_registered_flags().get_flags():
|
66
85
|
if input_command_flags.get_flags():
|
67
|
-
|
68
|
-
|
69
|
-
|
86
|
+
response: Response = self._structuring_input_flags(
|
87
|
+
handle_command, input_command_flags
|
88
|
+
)
|
89
|
+
command_handler.handling(response)
|
70
90
|
else:
|
71
|
-
|
72
|
-
|
91
|
+
response.status = Status.ALL_FLAGS_VALID
|
92
|
+
command_handler.handling(response)
|
73
93
|
else:
|
74
94
|
if input_command_flags.get_flags():
|
75
|
-
|
76
|
-
|
95
|
+
response.status = Status.UNDEFINED_FLAGS
|
96
|
+
response.undefined_flags = UndefinedInputFlags()
|
97
|
+
response.undefined_flags.add_flags(input_command_flags.get_flags())
|
98
|
+
command_handler.handling(response)
|
77
99
|
else:
|
78
|
-
|
79
|
-
|
80
|
-
|
100
|
+
response.status = Status.ALL_FLAGS_VALID
|
101
|
+
command_handler.handling(response)
|
81
102
|
|
82
|
-
|
103
|
+
@staticmethod
|
104
|
+
def _structuring_input_flags(
|
105
|
+
handled_command: Command, input_flags: InputFlags
|
106
|
+
) -> Response:
|
107
|
+
"""
|
108
|
+
Private. Validates flags of input command
|
109
|
+
:param handled_command: entity of the handled command
|
110
|
+
:param input_flags:
|
111
|
+
:return: entity of response as Response
|
112
|
+
"""
|
113
|
+
valid_input_flags: ValidInputFlags = ValidInputFlags()
|
114
|
+
invalid_value_input_flags: InvalidValueInputFlags = InvalidValueInputFlags()
|
115
|
+
undefined_input_flags: UndefinedInputFlags = UndefinedInputFlags()
|
83
116
|
for flag in input_flags:
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
117
|
+
flag_status: Literal["Undefined", "Valid", "Invalid"] = (
|
118
|
+
handled_command.validate_input_flag(flag)
|
119
|
+
)
|
120
|
+
match flag_status:
|
121
|
+
case "Valid":
|
122
|
+
valid_input_flags.add_flag(flag)
|
123
|
+
case "Undefined":
|
124
|
+
undefined_input_flags.add_flag(flag)
|
125
|
+
case "Invalid":
|
126
|
+
invalid_value_input_flags.add_flag(flag)
|
127
|
+
|
128
|
+
if (
|
129
|
+
not invalid_value_input_flags.get_flags()
|
130
|
+
and not undefined_input_flags.get_flags()
|
131
|
+
):
|
132
|
+
status = Status.ALL_FLAGS_VALID
|
133
|
+
elif (
|
134
|
+
invalid_value_input_flags.get_flags()
|
135
|
+
and not undefined_input_flags.get_flags()
|
136
|
+
):
|
137
|
+
status = Status.INVALID_VALUE_FLAGS
|
138
|
+
elif (
|
139
|
+
not invalid_value_input_flags.get_flags()
|
140
|
+
and undefined_input_flags.get_flags()
|
141
|
+
):
|
142
|
+
status = Status.UNDEFINED_FLAGS
|
143
|
+
else:
|
144
|
+
status = Status.UNDEFINED_AND_INVALID_FLAGS
|
89
145
|
|
146
|
+
return Response(
|
147
|
+
invalid_value_flags=invalid_value_input_flags,
|
148
|
+
valid_flags=valid_input_flags,
|
149
|
+
status=status,
|
150
|
+
undefined_flags=undefined_input_flags,
|
151
|
+
)
|
90
152
|
|
91
153
|
@staticmethod
|
92
|
-
def _validate_command(command: Command):
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
154
|
+
def _validate_command(command: Command | str) -> None:
|
155
|
+
"""
|
156
|
+
Private. Validates the command registered in handler
|
157
|
+
:param command: validated command
|
158
|
+
:return: None if command is valid else raise exception
|
159
|
+
"""
|
160
|
+
match type(command).__name__:
|
161
|
+
case "Command":
|
162
|
+
command_name: str = command.get_trigger()
|
163
|
+
if command_name.find(" ") != -1:
|
164
|
+
raise TriggerContainSpacesException()
|
165
|
+
flags: Flags = command.get_registered_flags()
|
166
|
+
if flags:
|
167
|
+
flags_name: list = [x.get_string_entity().lower() for x in flags]
|
168
|
+
if len(set(flags_name)) < len(flags_name):
|
169
|
+
raise RepeatedFlagNameException()
|
170
|
+
case "str":
|
171
|
+
if command.find(" ") != -1:
|
172
|
+
raise TriggerContainSpacesException()
|
103
173
|
|
104
174
|
@staticmethod
|
105
|
-
def _validate_func_args(
|
106
|
-
|
175
|
+
def _validate_func_args(func: Callable) -> None:
|
176
|
+
"""
|
177
|
+
Private. Validates the arguments of the handler
|
178
|
+
:param func: entity of the handler func
|
179
|
+
:return: None if func is valid else raise exception
|
180
|
+
"""
|
107
181
|
transferred_args = getfullargspec(func).args
|
108
|
-
if
|
109
|
-
if len(transferred_args) != 1:
|
110
|
-
raise TooManyTransferredArgsException()
|
111
|
-
elif registered_args.get_flags() and not transferred_args:
|
112
|
-
raise RequiredArgumentNotPassedException()
|
113
|
-
elif not registered_args.get_flags() and transferred_args:
|
182
|
+
if len(transferred_args) > 1:
|
114
183
|
raise TooManyTransferredArgsException()
|
184
|
+
elif len(transferred_args) == 0:
|
185
|
+
raise RequiredArgumentNotPassedException()
|
115
186
|
|
187
|
+
transferred_arg: str = transferred_args[0]
|
188
|
+
func_annotations: dict[str, Type] = get_annotations(func)
|
116
189
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
190
|
+
if arg_annotation := func_annotations.get(transferred_arg):
|
191
|
+
if arg_annotation is Response:
|
192
|
+
pass
|
193
|
+
else:
|
194
|
+
file_path: str = getsourcefile(func)
|
195
|
+
source_line: int = getsourcelines(func)[1] + 1
|
196
|
+
fprint = Console().print
|
197
|
+
fprint(
|
198
|
+
f'\nFile "{file_path}", line {source_line}\n[b red]WARNING:[/b red] [i]The typehint '
|
199
|
+
f"of argument([green]{transferred_arg}[/green]) passed to the handler is [/i][bold blue]{Response}[/bold blue],"
|
200
|
+
f" [i]but[/i] [bold blue]{arg_annotation}[/bold blue] [i]is specified[/i]\n",
|
201
|
+
highlight=False,
|
202
|
+
)
|
203
|
+
|
204
|
+
def set_command_register_ignore(self, _: bool) -> None:
|
205
|
+
"""
|
206
|
+
Private. Sets the router behavior on the input commands register
|
207
|
+
:param _: is command register ignore
|
208
|
+
:return: None
|
209
|
+
"""
|
210
|
+
self._ignore_command_register = _
|
211
|
+
|
212
|
+
def get_triggers(self) -> list[str]:
|
213
|
+
"""
|
214
|
+
Public. Gets registered triggers
|
215
|
+
:return: registered in router triggers as list[str]
|
216
|
+
"""
|
122
217
|
all_triggers: list[str] = []
|
123
218
|
for command_handler in self._command_handlers:
|
124
219
|
all_triggers.append(command_handler.get_handled_command().get_trigger())
|
125
220
|
return all_triggers
|
126
221
|
|
127
|
-
|
128
|
-
|
222
|
+
def get_aliases(self) -> list[str]:
|
223
|
+
"""
|
224
|
+
Public. Gets registered aliases
|
225
|
+
:return: registered in router aliases as list[str]
|
226
|
+
"""
|
129
227
|
all_aliases: list[str] = []
|
130
228
|
for command_handler in self._command_handlers:
|
131
229
|
if command_handler.get_handled_command().get_aliases():
|
132
230
|
all_aliases.extend(command_handler.get_handled_command().get_aliases())
|
133
231
|
return all_aliases
|
134
232
|
|
135
|
-
|
136
233
|
def get_command_handlers(self) -> CommandHandlers:
|
234
|
+
"""
|
235
|
+
Private. Gets registered command handlers
|
236
|
+
:return: registered command handlers as CommandHandlers
|
237
|
+
"""
|
137
238
|
return self._command_handlers
|
138
|
-
|
139
|
-
|
140
|
-
def get_name(self) -> str:
|
141
|
-
return self._name
|
142
|
-
|
143
|
-
|
144
|
-
def get_title(self) -> str | None:
|
145
|
-
return self._title
|
146
|
-
|
147
|
-
|
148
|
-
def set_title(self, title: str):
|
149
|
-
self._title = title
|