argenta 0.4.0__py3-none-any.whl → 0.4.1__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/entity.py +39 -18
- argenta/router/defaults.py +5 -0
- argenta/router/entity.py +4 -0
- {argenta-0.4.0.dist-info → argenta-0.4.1.dist-info}/METADATA +1 -1
- {argenta-0.4.0.dist-info → argenta-0.4.1.dist-info}/RECORD +7 -6
- {argenta-0.4.0.dist-info → argenta-0.4.1.dist-info}/WHEEL +1 -1
- {argenta-0.4.0.dist-info → argenta-0.4.1.dist-info}/LICENSE +0 -0
argenta/app/entity.py
CHANGED
@@ -2,9 +2,10 @@ from typing import Callable
|
|
2
2
|
from inspect import getfullargspec
|
3
3
|
import re
|
4
4
|
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from
|
5
|
+
from argenta.command import Command
|
6
|
+
from argenta.router import Router
|
7
|
+
from argenta.router.defaults import system_router
|
8
|
+
from argenta.command.exceptions import (UnprocessedInputFlagException,
|
8
9
|
RepeatedInputFlagsException,
|
9
10
|
EmptyInputCommandException)
|
10
11
|
from .exceptions import (InvalidRouterInstanceException,
|
@@ -29,6 +30,7 @@ class App:
|
|
29
30
|
line_separate: str = '',
|
30
31
|
command_group_description_separate: str = '',
|
31
32
|
repeat_command_groups: bool = True,
|
33
|
+
messages_on_startup: list[str] = None,
|
32
34
|
print_func: Callable[[str], None] = print) -> None:
|
33
35
|
self.prompt = prompt
|
34
36
|
self.print_func = print_func
|
@@ -43,6 +45,7 @@ class App:
|
|
43
45
|
self.command_group_description_separate = command_group_description_separate
|
44
46
|
self.ignore_command_register = ignore_command_register
|
45
47
|
self.repeat_command_groups = repeat_command_groups
|
48
|
+
self.messages_on_startup = messages_on_startup if messages_on_startup else []
|
46
49
|
|
47
50
|
self._routers: list[Router] = []
|
48
51
|
self._description_message_pattern: str = '[{command}] *=*=* {description}'
|
@@ -51,15 +54,20 @@ class App:
|
|
51
54
|
self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: "{raw_command}"')
|
52
55
|
self._empty_input_command_handler: Callable[[], None] = lambda: print_func(f'Empty input command')
|
53
56
|
self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_trigger()}")
|
57
|
+
self._exit_command_handler: Callable[[], None] = lambda: print_func(self.farewell_message)
|
54
58
|
|
55
59
|
|
56
60
|
def start_polling(self) -> None:
|
61
|
+
self._setup_system_router()
|
57
62
|
self._validate_number_of_routers()
|
58
63
|
self._validate_included_routers()
|
59
64
|
self._validate_all_router_commands()
|
60
65
|
|
61
66
|
self.print_func(self.initial_message)
|
62
67
|
|
68
|
+
for message in self.messages_on_startup:
|
69
|
+
self.print_func(message)
|
70
|
+
|
63
71
|
if not self.repeat_command_groups:
|
64
72
|
self._print_command_group_description()
|
65
73
|
self.print_func(self.prompt)
|
@@ -100,7 +108,7 @@ class App:
|
|
100
108
|
self.print_func(self.prompt)
|
101
109
|
continue
|
102
110
|
|
103
|
-
is_exit = self._is_exit_command(input_command
|
111
|
+
is_exit = self._is_exit_command(input_command)
|
104
112
|
if is_exit:
|
105
113
|
return
|
106
114
|
|
@@ -173,6 +181,18 @@ class App:
|
|
173
181
|
self._empty_input_command_handler = handler
|
174
182
|
|
175
183
|
|
184
|
+
def set_exit_command_handler(self, handler: Callable[[], None]) -> None:
|
185
|
+
args = getfullargspec(handler).args
|
186
|
+
if len(args) != 0:
|
187
|
+
raise IncorrectNumberOfHandlerArgsException()
|
188
|
+
else:
|
189
|
+
self._exit_command_handler = handler
|
190
|
+
|
191
|
+
|
192
|
+
def add_message_on_startup(self, message: str) -> None:
|
193
|
+
self.messages_on_startup.append(message)
|
194
|
+
|
195
|
+
|
176
196
|
def include_router(self, router: Router) -> None:
|
177
197
|
if not isinstance(router, Router):
|
178
198
|
raise InvalidRouterInstanceException()
|
@@ -214,14 +234,24 @@ class App:
|
|
214
234
|
raise RepeatedCommandInDifferentRoutersException()
|
215
235
|
|
216
236
|
|
217
|
-
def
|
218
|
-
|
237
|
+
def _setup_system_router(self):
|
238
|
+
system_router.set_title(self.system_points_title)
|
239
|
+
@system_router.command(Command(self.exit_command, self.exit_command_description))
|
240
|
+
def exit_command():
|
241
|
+
self._exit_command_handler()
|
242
|
+
|
243
|
+
if system_router not in [router['entity'] for router in self._registered_router_entities]:
|
244
|
+
self.include_router(system_router)
|
245
|
+
|
246
|
+
|
247
|
+
def _is_exit_command(self, command: Command):
|
248
|
+
if command.get_trigger().lower() == self.exit_command.lower():
|
219
249
|
if self.ignore_exit_command_register:
|
220
|
-
|
250
|
+
system_router.input_command_handler(command)
|
221
251
|
return True
|
222
252
|
else:
|
223
|
-
if command == self.exit_command:
|
224
|
-
|
253
|
+
if command.get_trigger() == self.exit_command:
|
254
|
+
system_router.input_command_handler(command)
|
225
255
|
return True
|
226
256
|
return False
|
227
257
|
|
@@ -250,12 +280,3 @@ class App:
|
|
250
280
|
)
|
251
281
|
)
|
252
282
|
self.print_func(self.command_group_description_separate)
|
253
|
-
|
254
|
-
self.print_func(self.system_points_title)
|
255
|
-
self.print_func(self._description_message_pattern.format(
|
256
|
-
command=self.exit_command,
|
257
|
-
description=self.exit_command_description
|
258
|
-
)
|
259
|
-
)
|
260
|
-
self.print_func(self.command_group_description_separate)
|
261
|
-
|
argenta/router/entity.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
argenta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
argenta/app/__init__.py,sha256=NoKJpO5inI4bEtptNj7BZtNpGQidCNoFSw2-JoK6P98,25
|
3
|
-
argenta/app/entity.py,sha256=
|
3
|
+
argenta/app/entity.py,sha256=9vRk66GQD-3kC--alv21gM_rqyA9ZzKfzXy0jVD6cO0,12506
|
4
4
|
argenta/app/exceptions.py,sha256=ruI_MwJQtBLrnWxJbKlSRE50c5FjnZ9qXJma34kPZhk,1253
|
5
5
|
argenta/command/__init__.py,sha256=yRSj5CtLjxwjKiokUGdSmuBZPOF_qheRyG0NW1pv7vo,27
|
6
6
|
argenta/command/entity.py,sha256=uICQk5zaD_IG52q2IpFTDiGkTK0G6guPR6Eb9Y-3n0E,4454
|
@@ -11,9 +11,10 @@ argenta/command/flag/entity.py,sha256=osMAh-PVP_1MhRhe4Zf1NmJu5NJWAyY6oOKT9mtZnW
|
|
11
11
|
argenta/command/flag/flags_group/__init__.py,sha256=f1q3albNnoQYrY56Exb75oh62miTdxD0ALo5aBWW9_g,30
|
12
12
|
argenta/command/flag/flags_group/entity.py,sha256=NcyKjC_N-8d4xARkVCLSK8-PoPrKjSlIbR4SHSa7_us,985
|
13
13
|
argenta/router/__init__.py,sha256=vIU2o3JJ7misRm9mUzUQw5HdverdMDfvHNzkWuYFRBY,26
|
14
|
-
argenta/router/
|
14
|
+
argenta/router/defaults.py,sha256=huftOg1HMjrT_R2SHHOL4eJ5uZHspNEYBSg-mCq9xhU,126
|
15
|
+
argenta/router/entity.py,sha256=w4_LO3jVbQPMu8GHjSW6q-_AdQ_IPQkGJHjYaCVXw-Q,5195
|
15
16
|
argenta/router/exceptions.py,sha256=NseEKrhwvG-H5_qdN-hzq83eJ98jku-PzHspz4CG9PM,796
|
16
|
-
argenta-0.4.
|
17
|
-
argenta-0.4.
|
18
|
-
argenta-0.4.
|
19
|
-
argenta-0.4.
|
17
|
+
argenta-0.4.1.dist-info/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
|
18
|
+
argenta-0.4.1.dist-info/METADATA,sha256=r7hxvBwmXnaa3GDn3x3bvUlIode_EGFW1E2iCB6wkZY,18187
|
19
|
+
argenta-0.4.1.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
20
|
+
argenta-0.4.1.dist-info/RECORD,,
|
File without changes
|