argenta 0.3.0a0__tar.gz → 0.3.2__tar.gz
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-0.3.0a0 → argenta-0.3.2}/PKG-INFO +1 -1
- argenta-0.3.2/argenta/app/__init__.py +3 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/app/entity.py +72 -41
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/app/exceptions.py +0 -26
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/input_comand/entity.py +4 -4
- argenta-0.3.2/argenta/command/input_comand/exceptions.py +37 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/params/flag/flags_group/entity.py +3 -0
- argenta-0.3.2/argenta/router/__init__.py +2 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/router/entity.py +55 -43
- argenta-0.3.2/argenta/router/exceptions.py +36 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/pyproject.toml +1 -3
- argenta-0.3.0a0/argenta/app/__init__.py +0 -7
- argenta-0.3.0a0/argenta/command/input_comand/__pycache__/__init__.cpython-313.pyc +0 -0
- argenta-0.3.0a0/argenta/command/input_comand/__pycache__/entity.cpython-313.pyc +0 -0
- argenta-0.3.0a0/argenta/command/input_comand/__pycache__/exceptions.cpython-313.pyc +0 -0
- argenta-0.3.0a0/argenta/command/input_comand/exceptions.py +0 -24
- argenta-0.3.0a0/argenta/router/__init__.py +0 -3
- argenta-0.3.0a0/argenta/router/exceptions.py +0 -18
- {argenta-0.3.0a0 → argenta-0.3.2}/LICENSE +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/README.md +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/__init__.py +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/__init__.py +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/entity.py +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/exceptions.py +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/input_comand/__init__.py +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/params/__init__.py +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/params/flag/__init__.py +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/params/flag/entity.py +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/params/flag/flags_group/__init__.py +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/params/flag/input_flag/__init__.py +0 -0
- {argenta-0.3.0a0 → argenta-0.3.2}/argenta/command/params/flag/input_flag/entity.py +0 -0
@@ -1,14 +1,17 @@
|
|
1
1
|
from typing import Callable
|
2
|
+
from inspect import getfullargspec
|
3
|
+
|
2
4
|
from ..command.entity import Command
|
3
|
-
from argenta.command.input_comand.entity import InputCommand
|
4
|
-
from argenta.command.input_comand.exceptions import InvalidInputFlagException
|
5
5
|
from ..router.entity import Router
|
6
|
+
from ..command.input_comand.entity import InputCommand
|
7
|
+
from ..command.input_comand.exceptions import (UnprocessedInputFlagException,
|
8
|
+
InvalidInputFlagsHandlerHasBeenAlreadyCreatedException,
|
9
|
+
IncorrectNumberOfHandlerArgsException,
|
10
|
+
UnknownCommandHandlerHasBeenAlreadyCreatedException,
|
11
|
+
RepeatedInputFlagsException,
|
12
|
+
RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException)
|
6
13
|
from .exceptions import (InvalidRouterInstanceException,
|
7
14
|
InvalidDescriptionMessagePatternException,
|
8
|
-
OnlyOneMainRouterIsAllowedException,
|
9
|
-
MissingMainRouterException,
|
10
|
-
MissingHandlerForUnknownCommandsException,
|
11
|
-
HandlerForUnknownCommandsOnNonMainRouterException,
|
12
15
|
NoRegisteredRoutersException,
|
13
16
|
NoRegisteredHandlersException,
|
14
17
|
RepeatedCommandInDifferentRoutersException)
|
@@ -44,6 +47,9 @@ class App:
|
|
44
47
|
self.repeat_command_groups = repeat_command_groups
|
45
48
|
|
46
49
|
self._routers: list[Router] = []
|
50
|
+
self._invalid_input_flags_handler: Callable[[str], None] | None = None
|
51
|
+
self._repeated_input_flags_handler: Callable[[str], None] | None = None
|
52
|
+
self._unknown_command_handler: Callable[[Command], None] | None = None
|
47
53
|
self._registered_router_entities: list[dict[str, str | list[dict[str, Callable[[], None] | Command]] | Router]] = []
|
48
54
|
self._app_main_router: Router | None = None
|
49
55
|
self._description_message_pattern: str = '[{command}] *=*=* {description}'
|
@@ -52,7 +58,6 @@ class App:
|
|
52
58
|
def start_polling(self) -> None:
|
53
59
|
self._validate_number_of_routers()
|
54
60
|
self._validate_included_routers()
|
55
|
-
self._validate_main_router()
|
56
61
|
self._validate_all_router_commands()
|
57
62
|
|
58
63
|
self.print_func(self.initial_message)
|
@@ -67,11 +72,26 @@ class App:
|
|
67
72
|
self.print_func(self.prompt)
|
68
73
|
|
69
74
|
raw_command: str = input()
|
75
|
+
|
70
76
|
try:
|
71
77
|
input_command: InputCommand = InputCommand.parse(raw_command=raw_command)
|
72
|
-
except
|
78
|
+
except UnprocessedInputFlagException:
|
79
|
+
self.print_func(self.line_separate)
|
80
|
+
if self._invalid_input_flags_handler:
|
81
|
+
self._invalid_input_flags_handler(raw_command)
|
82
|
+
else:
|
83
|
+
self.print_func(f'Incorrect flag syntax: "{raw_command}"')
|
84
|
+
self.print_func(self.line_separate)
|
85
|
+
if not self.repeat_command_groups:
|
86
|
+
self.print_func(self.prompt)
|
87
|
+
continue
|
88
|
+
except RepeatedInputFlagsException:
|
89
|
+
self.print_func(self.line_separate)
|
90
|
+
if self._repeated_input_flags_handler:
|
91
|
+
self._repeated_input_flags_handler(raw_command)
|
92
|
+
else:
|
93
|
+
self.print_func(f'Repeated input flags: "{raw_command}"')
|
73
94
|
self.print_func(self.line_separate)
|
74
|
-
self.print_func(self.command_group_description_separate)
|
75
95
|
if not self.repeat_command_groups:
|
76
96
|
self.print_func(self.prompt)
|
77
97
|
continue
|
@@ -79,7 +99,8 @@ class App:
|
|
79
99
|
self._checking_command_for_exit_command(input_command.get_string_entity())
|
80
100
|
self.print_func(self.line_separate)
|
81
101
|
|
82
|
-
is_unknown_command: bool = self._check_is_command_unknown(input_command
|
102
|
+
is_unknown_command: bool = self._check_is_command_unknown(input_command)
|
103
|
+
|
83
104
|
if is_unknown_command:
|
84
105
|
if not self.repeat_command_groups:
|
85
106
|
self.print_func(self.prompt)
|
@@ -111,8 +132,37 @@ class App:
|
|
111
132
|
self._description_message_pattern: str = pattern
|
112
133
|
|
113
134
|
|
114
|
-
def
|
115
|
-
|
135
|
+
def set_invalid_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
136
|
+
if self._invalid_input_flags_handler:
|
137
|
+
raise InvalidInputFlagsHandlerHasBeenAlreadyCreatedException()
|
138
|
+
else:
|
139
|
+
args = getfullargspec(handler).args
|
140
|
+
if len(args) != 1:
|
141
|
+
raise IncorrectNumberOfHandlerArgsException()
|
142
|
+
else:
|
143
|
+
self._invalid_input_flags_handler = handler
|
144
|
+
|
145
|
+
|
146
|
+
def set_repeated_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
147
|
+
if self._repeated_input_flags_handler:
|
148
|
+
raise RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException()
|
149
|
+
else:
|
150
|
+
args = getfullargspec(handler).args
|
151
|
+
if len(args) != 1:
|
152
|
+
raise IncorrectNumberOfHandlerArgsException()
|
153
|
+
else:
|
154
|
+
self._repeated_input_flags_handler = handler
|
155
|
+
|
156
|
+
|
157
|
+
def set_unknown_command_handler(self, handler: Callable[[str], None]) -> None:
|
158
|
+
if self._unknown_command_handler:
|
159
|
+
raise UnknownCommandHandlerHasBeenAlreadyCreatedException()
|
160
|
+
else:
|
161
|
+
args = getfullargspec(handler).args
|
162
|
+
if len(args) != 1:
|
163
|
+
raise IncorrectNumberOfHandlerArgsException()
|
164
|
+
else:
|
165
|
+
self._unknown_command_handler = handler
|
116
166
|
|
117
167
|
|
118
168
|
def get_all_app_commands(self) -> list[str]:
|
@@ -123,17 +173,10 @@ class App:
|
|
123
173
|
return all_commands
|
124
174
|
|
125
175
|
|
126
|
-
def include_router(self, router: Router
|
176
|
+
def include_router(self, router: Router) -> None:
|
127
177
|
if not isinstance(router, Router):
|
128
178
|
raise InvalidRouterInstanceException()
|
129
179
|
|
130
|
-
if is_main:
|
131
|
-
if not self._app_main_router:
|
132
|
-
self._app_main_router = router
|
133
|
-
router.set_router_as_main()
|
134
|
-
else:
|
135
|
-
raise OnlyOneMainRouterIsAllowedException(self._app_main_router.get_name())
|
136
|
-
|
137
180
|
router.set_ignore_command_register(self.ignore_command_register)
|
138
181
|
self._routers.append(router)
|
139
182
|
|
@@ -155,23 +198,6 @@ class App:
|
|
155
198
|
raise NoRegisteredHandlersException(router.get_name())
|
156
199
|
|
157
200
|
|
158
|
-
def _validate_main_router(self):
|
159
|
-
if not self._app_main_router:
|
160
|
-
if len(self._routers) > 1:
|
161
|
-
raise MissingMainRouterException()
|
162
|
-
else:
|
163
|
-
router = self._routers[0]
|
164
|
-
router.set_router_as_main()
|
165
|
-
self._app_main_router = router
|
166
|
-
|
167
|
-
if not self._app_main_router.unknown_command_func:
|
168
|
-
raise MissingHandlerForUnknownCommandsException()
|
169
|
-
|
170
|
-
for router in self._routers:
|
171
|
-
if router.unknown_command_func and self._app_main_router is not router:
|
172
|
-
raise HandlerForUnknownCommandsOnNonMainRouterException()
|
173
|
-
|
174
|
-
|
175
201
|
def _validate_all_router_commands(self) -> None:
|
176
202
|
for idx in range(len(self._registered_router_entities)):
|
177
203
|
current_router: Router = self._registered_router_entities[idx]['entity']
|
@@ -199,17 +225,22 @@ class App:
|
|
199
225
|
exit(0)
|
200
226
|
|
201
227
|
|
202
|
-
def _check_is_command_unknown(self, command:
|
228
|
+
def _check_is_command_unknown(self, command: Command):
|
203
229
|
registered_router_entities: list[dict[str, str | list[dict[str, Callable[[], None] | Command]] | Router]] = self._registered_router_entities
|
204
230
|
for router_entity in registered_router_entities:
|
205
231
|
for command_entity in router_entity['commands']:
|
206
|
-
if command_entity['command'].get_string_entity().lower() == command.lower():
|
232
|
+
if command_entity['command'].get_string_entity().lower() == command.get_string_entity().lower():
|
207
233
|
if self.ignore_command_register:
|
208
234
|
return False
|
209
235
|
else:
|
210
|
-
if command_entity['command'].get_string_entity() == command:
|
236
|
+
if command_entity['command'].get_string_entity() == command.get_string_entity():
|
211
237
|
return False
|
212
|
-
|
238
|
+
|
239
|
+
if self._unknown_command_handler:
|
240
|
+
self._unknown_command_handler(command)
|
241
|
+
else:
|
242
|
+
print(f"Unknown command: {command.get_string_entity()}")
|
243
|
+
|
213
244
|
self.print_func(self.line_separate)
|
214
245
|
self.print_func(self.command_group_description_separate)
|
215
246
|
return True
|
@@ -13,32 +13,6 @@ class InvalidDescriptionMessagePatternException(Exception):
|
|
13
13
|
f"Your pattern: {self.pattern}")
|
14
14
|
|
15
15
|
|
16
|
-
class OnlyOneMainRouterIsAllowedException(Exception):
|
17
|
-
def __init__(self, existing_main_router):
|
18
|
-
self.existing_main_router = existing_main_router
|
19
|
-
|
20
|
-
def __str__(self):
|
21
|
-
return ("Only One Main Router Allowed\n"
|
22
|
-
f"Existing main router is: {self.existing_main_router}")
|
23
|
-
|
24
|
-
|
25
|
-
class MissingMainRouterException(Exception):
|
26
|
-
def __str__(self):
|
27
|
-
return ("Missing Main Router\n"
|
28
|
-
"One of the registered routers must be the main one")
|
29
|
-
|
30
|
-
|
31
|
-
class MissingHandlerForUnknownCommandsException(Exception):
|
32
|
-
def __str__(self):
|
33
|
-
return ("Missing Handlers For Unknown Commands On The Main Router\n"
|
34
|
-
"The main router must have a declared handler for unknown commands")
|
35
|
-
|
36
|
-
|
37
|
-
class HandlerForUnknownCommandsOnNonMainRouterException(Exception):
|
38
|
-
def __str__(self):
|
39
|
-
return '\nThe handler for unknown commands can only be declared for the main router'
|
40
|
-
|
41
|
-
|
42
16
|
class NoRegisteredRoutersException(Exception):
|
43
17
|
def __str__(self):
|
44
18
|
return "No Registered Router Found"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from ..input_comand.exceptions import
|
1
|
+
from ..input_comand.exceptions import UnprocessedInputFlagException, RepeatedInputFlagsException
|
2
2
|
from ..entity import Command
|
3
3
|
from ..params.flag.flags_group.entity import FlagsGroup
|
4
4
|
from ..params.flag.input_flag.entity import InputFlag
|
@@ -29,12 +29,12 @@ class InputCommand(Command, Generic[T]):
|
|
29
29
|
if _.startswith('-'):
|
30
30
|
flag_prefix_last_symbol_index = _.rfind('-')
|
31
31
|
if current_flag_name or len(_) < 2 or len(_[:flag_prefix_last_symbol_index]) > 3:
|
32
|
-
raise
|
32
|
+
raise UnprocessedInputFlagException()
|
33
33
|
else:
|
34
34
|
current_flag_name = _
|
35
35
|
else:
|
36
36
|
if not current_flag_name:
|
37
|
-
raise
|
37
|
+
raise UnprocessedInputFlagException()
|
38
38
|
else:
|
39
39
|
current_flag_value = _
|
40
40
|
if current_flag_name and current_flag_value:
|
@@ -55,7 +55,7 @@ class InputCommand(Command, Generic[T]):
|
|
55
55
|
current_flag_name = None
|
56
56
|
current_flag_value = None
|
57
57
|
if any([current_flag_name, current_flag_value]):
|
58
|
-
raise
|
58
|
+
raise UnprocessedInputFlagException()
|
59
59
|
if len(flags.get_flags()) == 0:
|
60
60
|
return InputCommand(command=command)
|
61
61
|
else:
|
@@ -0,0 +1,37 @@
|
|
1
|
+
from ..params.flag.input_flag.entity import InputFlag
|
2
|
+
|
3
|
+
|
4
|
+
class UnprocessedInputFlagException(Exception):
|
5
|
+
def __str__(self):
|
6
|
+
return "Unprocessed Input Flags"
|
7
|
+
|
8
|
+
|
9
|
+
class RepeatedInputFlagsException(Exception):
|
10
|
+
def __init__(self, flag: InputFlag):
|
11
|
+
self.flag = flag
|
12
|
+
def __str__(self):
|
13
|
+
return ("Repeated Input Flags\n"
|
14
|
+
f"Duplicate flag was detected in the input: '{self.flag.get_string_entity()}'")
|
15
|
+
|
16
|
+
|
17
|
+
class InvalidInputFlagsHandlerHasBeenAlreadyCreatedException(Exception):
|
18
|
+
def __str__(self):
|
19
|
+
return "Invalid Input Flags Handler has already been created"
|
20
|
+
|
21
|
+
|
22
|
+
class RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException(Exception):
|
23
|
+
def __str__(self):
|
24
|
+
return "Repeated Input Flags Handler has already been created"
|
25
|
+
|
26
|
+
|
27
|
+
class UnknownCommandHandlerHasBeenAlreadyCreatedException(Exception):
|
28
|
+
def __str__(self):
|
29
|
+
return "Unknown Command Handler has already been created"
|
30
|
+
|
31
|
+
|
32
|
+
class IncorrectNumberOfHandlerArgsException(Exception):
|
33
|
+
def __str__(self):
|
34
|
+
return "Incorrect Input Flags Handler has incorrect number of arguments"
|
35
|
+
|
36
|
+
|
37
|
+
|
@@ -1,10 +1,13 @@
|
|
1
1
|
from typing import Callable, Any
|
2
|
+
from inspect import getfullargspec
|
2
3
|
from ..command.entity import Command
|
3
4
|
from ..command.input_comand.entity import InputCommand
|
4
|
-
from ..command.input_comand.exceptions import InvalidInputFlagException
|
5
5
|
from ..command.params.flag.flags_group.entity import FlagsGroup
|
6
|
-
from ..router.exceptions import (
|
7
|
-
|
6
|
+
from ..router.exceptions import (RepeatedCommandException, RepeatedFlagNameException,
|
7
|
+
TooManyTransferredArgsException,
|
8
|
+
RequiredArgumentNotPassedException,
|
9
|
+
NotValidInputFlagHandlerHasBeenAlreadyCreatedException,
|
10
|
+
IncorrectNumberOfHandlerArgsException)
|
8
11
|
|
9
12
|
|
10
13
|
class Router:
|
@@ -16,9 +19,9 @@ class Router:
|
|
16
19
|
self.name = name
|
17
20
|
|
18
21
|
self._command_entities: list[dict[str, Callable[[], None] | Command]] = []
|
19
|
-
self.
|
20
|
-
|
21
|
-
self.
|
22
|
+
self._ignore_command_register: bool = False
|
23
|
+
|
24
|
+
self._not_valid_flag_handler: Callable[[Command], None] | None = None
|
22
25
|
|
23
26
|
|
24
27
|
def command(self, command: Command) -> Callable[[Any], Any]:
|
@@ -26,6 +29,7 @@ class Router:
|
|
26
29
|
self._validate_command(command)
|
27
30
|
|
28
31
|
def command_decorator(func):
|
32
|
+
Router._validate_func_args(command, func)
|
29
33
|
self._command_entities.append({'handler_func': func,
|
30
34
|
'command': command})
|
31
35
|
def wrapper(*args, **kwargs):
|
@@ -34,52 +38,55 @@ class Router:
|
|
34
38
|
|
35
39
|
return command_decorator
|
36
40
|
|
41
|
+
def not_valid_input_flag(self, func):
|
42
|
+
if self._not_valid_flag_handler:
|
43
|
+
raise NotValidInputFlagHandlerHasBeenAlreadyCreatedException()
|
44
|
+
else:
|
45
|
+
processed_args = getfullargspec(func).args
|
46
|
+
if len(processed_args) != 1:
|
47
|
+
raise IncorrectNumberOfHandlerArgsException()
|
48
|
+
else:
|
49
|
+
self._not_valid_flag_handler = func
|
50
|
+
def wrapper(*args, **kwargs):
|
51
|
+
return func(*args, **kwargs)
|
37
52
|
|
38
|
-
|
39
|
-
if self.unknown_command_func is not None:
|
40
|
-
raise UnknownCommandHandlerHasAlreadyBeenCreatedException()
|
41
|
-
|
42
|
-
self.unknown_command_func: Callable = func
|
43
|
-
|
44
|
-
def wrapper(*args, **kwargs):
|
45
|
-
return func(*args, **kwargs)
|
46
|
-
return wrapper
|
53
|
+
return wrapper
|
47
54
|
|
48
55
|
|
49
56
|
def input_command_handler(self, input_command: InputCommand):
|
50
57
|
input_command_name: str = input_command.get_string_entity()
|
58
|
+
input_command_flags: FlagsGroup = input_command.get_input_flags()
|
51
59
|
for command_entity in self._command_entities:
|
52
60
|
if input_command_name.lower() == command_entity['command'].get_string_entity().lower():
|
53
|
-
if
|
54
|
-
if
|
55
|
-
for flag in
|
61
|
+
if command_entity['command'].get_flags():
|
62
|
+
if input_command_flags:
|
63
|
+
for flag in input_command_flags:
|
56
64
|
is_valid = command_entity['command'].validate_input_flag(flag)
|
57
65
|
if not is_valid:
|
58
|
-
|
59
|
-
|
66
|
+
if self._not_valid_flag_handler:
|
67
|
+
self._not_valid_flag_handler(input_command)
|
68
|
+
else:
|
69
|
+
print(f"Undefined or incorrect input flag: '{flag.get_string_entity()} {flag.get_value()}'")
|
70
|
+
return
|
71
|
+
return command_entity['handler_func'](input_command_flags)
|
60
72
|
else:
|
61
|
-
return command_entity['handler_func']()
|
73
|
+
return command_entity['handler_func'](FlagsGroup(None))
|
62
74
|
else:
|
63
|
-
if
|
64
|
-
if
|
65
|
-
|
66
|
-
is_valid = command_entity['command'].validate_input_flag(flag)
|
67
|
-
if not is_valid:
|
68
|
-
raise InvalidInputFlagException(flag)
|
69
|
-
return command_entity['handler_func'](input_command.get_input_flags())
|
75
|
+
if input_command_flags:
|
76
|
+
if self._not_valid_flag_handler:
|
77
|
+
self._not_valid_flag_handler(input_command)
|
70
78
|
else:
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
self.unknown_command_func(unknown_command)
|
79
|
+
print(f"Undefined or incorrect input flag: '{input_command_flags[0].get_string_entity()} {input_command_flags[0].get_value()}'")
|
80
|
+
return
|
81
|
+
else:
|
82
|
+
return command_entity['handler_func']()
|
76
83
|
|
77
84
|
|
78
85
|
def _validate_command(self, command: Command):
|
79
86
|
command_name: str = command.get_string_entity()
|
80
|
-
if
|
87
|
+
if command_name in self.get_all_commands():
|
81
88
|
raise RepeatedCommandException()
|
82
|
-
if self.
|
89
|
+
if self._ignore_command_register:
|
83
90
|
if command_name.lower() in [x.lower() for x in self.get_all_commands()]:
|
84
91
|
raise RepeatedCommandException()
|
85
92
|
|
@@ -90,14 +97,21 @@ class Router:
|
|
90
97
|
raise RepeatedFlagNameException()
|
91
98
|
|
92
99
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
100
|
+
@staticmethod
|
101
|
+
def _validate_func_args(command: Command, func: Callable):
|
102
|
+
registered_args = command.get_flags()
|
103
|
+
transferred_args = getfullargspec(func).args
|
104
|
+
if registered_args and transferred_args:
|
105
|
+
if len(transferred_args) != 1:
|
106
|
+
raise TooManyTransferredArgsException()
|
107
|
+
elif registered_args and not transferred_args:
|
108
|
+
raise RequiredArgumentNotPassedException()
|
109
|
+
elif not registered_args and transferred_args:
|
110
|
+
raise TooManyTransferredArgsException()
|
97
111
|
|
98
112
|
|
99
113
|
def set_ignore_command_register(self, ignore_command_register: bool):
|
100
|
-
self.
|
114
|
+
self._ignore_command_register = ignore_command_register
|
101
115
|
|
102
116
|
|
103
117
|
def get_command_entities(self) -> list[dict[str, Callable[[], None] | Command]]:
|
@@ -116,11 +130,9 @@ class Router:
|
|
116
130
|
return {
|
117
131
|
'title': self.title,
|
118
132
|
'name': self.name,
|
119
|
-
'ignore_command_register': self.
|
133
|
+
'ignore_command_register': self._ignore_command_register,
|
120
134
|
'attributes': {
|
121
135
|
'command_entities': self._command_entities,
|
122
|
-
'unknown_command_func': self.unknown_command_func,
|
123
|
-
'is_main_router': self._is_main_router
|
124
136
|
}
|
125
137
|
|
126
138
|
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
from ..command.params.flag.input_flag.entity import InputFlag
|
2
|
+
|
3
|
+
|
4
|
+
class InvalidDescriptionInstanceException(Exception):
|
5
|
+
def __str__(self):
|
6
|
+
return "Invalid Description Instance"
|
7
|
+
|
8
|
+
|
9
|
+
class RepeatedCommandException(Exception):
|
10
|
+
def __str__(self):
|
11
|
+
return "Commands in handler cannot be repeated"
|
12
|
+
|
13
|
+
|
14
|
+
class RepeatedFlagNameException(Exception):
|
15
|
+
def __str__(self):
|
16
|
+
return "Repeated flag name in register command"
|
17
|
+
|
18
|
+
|
19
|
+
class TooManyTransferredArgsException(Exception):
|
20
|
+
def __str__(self):
|
21
|
+
return "Too many transferred arguments"
|
22
|
+
|
23
|
+
|
24
|
+
class RequiredArgumentNotPassedException(Exception):
|
25
|
+
def __str__(self):
|
26
|
+
return "Required argument not passed"
|
27
|
+
|
28
|
+
|
29
|
+
class NotValidInputFlagHandlerHasBeenAlreadyCreatedException(Exception):
|
30
|
+
def __str__(self):
|
31
|
+
return "Invalid Input Flag Handler has already been created"
|
32
|
+
|
33
|
+
|
34
|
+
class IncorrectNumberOfHandlerArgsException(Exception):
|
35
|
+
def __str__(self):
|
36
|
+
return "Incorrect Input Flags Handler has incorrect number of arguments"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "argenta"
|
3
|
-
version = "0.3.
|
3
|
+
version = "0.3.2"
|
4
4
|
description = "python library for creating custom shells"
|
5
5
|
authors = [
|
6
6
|
{name = "kolo",email = "kolo.is.main@gmail.com"}
|
@@ -33,6 +33,4 @@ numpy = "^2.2.2"
|
|
33
33
|
word2number = "^1.1"
|
34
34
|
numexpr = "^2.10.2"
|
35
35
|
requests = "^2.32.3"
|
36
|
-
tqdm = "^4.67.1"
|
37
|
-
setuptools = "^75.8.0"
|
38
36
|
|
@@ -1,7 +0,0 @@
|
|
1
|
-
from .entity import App
|
2
|
-
from .exceptions import (HandlerForUnknownCommandsOnNonMainRouterException,
|
3
|
-
InvalidDescriptionMessagePatternException,
|
4
|
-
InvalidRouterInstanceException,
|
5
|
-
OnlyOneMainRouterIsAllowedException,
|
6
|
-
MissingMainRouterException,
|
7
|
-
MissingHandlerForUnknownCommandsException)
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,24 +0,0 @@
|
|
1
|
-
from ..params.flag.input_flag.entity import InputFlag
|
2
|
-
|
3
|
-
|
4
|
-
class InvalidInputFlagException(Exception):
|
5
|
-
def __init__(self, flag: InputFlag):
|
6
|
-
self.flag = flag
|
7
|
-
def __str__(self):
|
8
|
-
return ("Invalid Input Flags\n"
|
9
|
-
f"Unknown or invalid input flag: '{self.flag.get_string_entity()} {self.flag.get_value()}'")
|
10
|
-
|
11
|
-
class IncorrectInputFlagException(Exception):
|
12
|
-
def __str__(self):
|
13
|
-
return "Incorrect Input Flags"
|
14
|
-
|
15
|
-
|
16
|
-
class RepeatedInputFlagsException(Exception):
|
17
|
-
def __init__(self, flag: InputFlag):
|
18
|
-
self.flag = flag
|
19
|
-
def __str__(self):
|
20
|
-
return ("Repeated Input Flags\n"
|
21
|
-
f"Duplicate flag was detected in the input: '{self.flag.get_string_entity()}'")
|
22
|
-
|
23
|
-
|
24
|
-
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class InvalidDescriptionInstanceException(Exception):
|
2
|
-
def __str__(self):
|
3
|
-
return "Invalid Description Instance"
|
4
|
-
|
5
|
-
|
6
|
-
class UnknownCommandHandlerHasAlreadyBeenCreatedException(Exception):
|
7
|
-
def __str__(self):
|
8
|
-
return "Only one unknown command handler can be declared"
|
9
|
-
|
10
|
-
|
11
|
-
class RepeatedCommandException(Exception):
|
12
|
-
def __str__(self):
|
13
|
-
return "Commands in handler cannot be repeated"
|
14
|
-
|
15
|
-
|
16
|
-
class RepeatedFlagNameException(Exception):
|
17
|
-
def __str__(self):
|
18
|
-
return "Repeated flag name in register command"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|