argenta 0.4.9__tar.gz → 0.4.10__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.4.9 → argenta-0.4.10}/PKG-INFO +1 -1
- argenta-0.4.10/argenta/app/__init__.py +3 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/app/models.py +93 -67
- argenta-0.4.10/argenta/command/__init__.py +3 -0
- argenta-0.4.10/argenta/command/flag/__init__.py +4 -0
- {argenta-0.4.9 → argenta-0.4.10}/pyproject.toml +1 -1
- argenta-0.4.9/argenta/app/__init__.py +0 -3
- argenta-0.4.9/argenta/command/__init__.py +0 -3
- argenta-0.4.9/argenta/command/flag/__init__.py +0 -4
- {argenta-0.4.9 → argenta-0.4.10}/LICENSE +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/README.md +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/__init__.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/app/defaults.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/app/dividing_line/__init__.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/app/dividing_line/models.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/app/exceptions.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/app/registered_routers/__init__.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/app/registered_routers/entity.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/command/exceptions.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/command/flag/defaults.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/command/flag/models.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/command/models.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/router/__init__.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/router/command_handler/__init__.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/router/command_handler/entity.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/router/command_handlers/__init__.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/router/command_handlers/entity.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/router/defaults.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/router/entity.py +0 -0
- {argenta-0.4.9 → argenta-0.4.10}/argenta/router/exceptions.py +0 -0
@@ -21,7 +21,7 @@ from argenta.app.registered_routers.entity import RegisteredRouters
|
|
21
21
|
|
22
22
|
|
23
23
|
|
24
|
-
class
|
24
|
+
class AppInit:
|
25
25
|
def __init__(self,
|
26
26
|
prompt: str = '[italic dim bold]What do you want to do?\n',
|
27
27
|
initial_message: str = '\nArgenta\n',
|
@@ -44,40 +44,72 @@ class BaseApp:
|
|
44
44
|
self._repeat_command_groups_description = repeat_command_groups
|
45
45
|
self._full_override_system_messages = full_override_system_messages
|
46
46
|
|
47
|
-
self.
|
48
|
-
self.
|
47
|
+
self._farewell_message = farewell_message
|
48
|
+
self._initial_message = initial_message
|
49
49
|
|
50
50
|
self._description_message_pattern: str = '[bold red][{command}][/bold red] [blue dim]*=*=*[/blue dim] [bold yellow italic]{description}'
|
51
51
|
self._registered_routers: RegisteredRouters = RegisteredRouters()
|
52
52
|
self._messages_on_startup = []
|
53
53
|
|
54
|
-
self.
|
55
|
-
self.
|
56
|
-
self.
|
57
|
-
self.
|
58
|
-
self.
|
54
|
+
self._invalid_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'[red bold]Incorrect flag syntax: {raw_command}')
|
55
|
+
self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'[red bold]Repeated input flags: {raw_command}')
|
56
|
+
self._empty_input_command_handler: Callable[[], None] = lambda: print_func('[red bold]Empty input command')
|
57
|
+
self._unknown_command_handler: Callable[[InputCommand], None] = lambda command: print_func(f"[red bold]Unknown command: {command.get_trigger()}")
|
58
|
+
self._exit_command_handler: Callable[[], None] = lambda: print_func(self._farewell_message)
|
59
59
|
|
60
|
-
self._setup_default_view()
|
61
60
|
|
61
|
+
class AppSetters(AppInit):
|
62
|
+
def set_description_message_pattern(self, pattern: str) -> None:
|
63
|
+
first_check = re.match(r'.*{command}.*', pattern)
|
64
|
+
second_check = re.match(r'.*{description}.*', pattern)
|
62
65
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
f'[red i]github.com/koloideal/Argenta[/red i] | [red bold i]made by kolo[/red bold i]\n')
|
66
|
+
if bool(first_check) and bool(second_check):
|
67
|
+
self._description_message_pattern: str = pattern
|
68
|
+
else:
|
69
|
+
raise InvalidDescriptionMessagePatternException(pattern)
|
68
70
|
|
69
71
|
|
70
|
-
def
|
71
|
-
|
72
|
-
raise NoRegisteredRoutersException()
|
72
|
+
def set_invalid_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
73
|
+
self._invalid_input_flags_handler = handler
|
73
74
|
|
74
75
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
def set_repeated_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
77
|
+
self._repeated_input_flags_handler = handler
|
78
|
+
|
79
|
+
|
80
|
+
def set_unknown_command_handler(self, handler: Callable[[str], None]) -> None:
|
81
|
+
self._unknown_command_handler = handler
|
82
|
+
|
79
83
|
|
84
|
+
def set_empty_command_handler(self, handler: Callable[[], None]) -> None:
|
85
|
+
self._empty_input_command_handler = handler
|
80
86
|
|
87
|
+
|
88
|
+
def set_exit_command_handler(self, handler: Callable[[], None]) -> None:
|
89
|
+
self._exit_command_handler = handler
|
90
|
+
|
91
|
+
|
92
|
+
class AppPrinters(AppInit):
|
93
|
+
def _print_command_group_description(self):
|
94
|
+
for registered_router in self._registered_routers:
|
95
|
+
self._print_func(registered_router.get_title())
|
96
|
+
for command_handler in registered_router.get_command_handlers():
|
97
|
+
self._print_func(self._description_message_pattern.format(
|
98
|
+
command=command_handler.get_handled_command().get_trigger(),
|
99
|
+
description=command_handler.get_handled_command().get_description()))
|
100
|
+
self._print_func('')
|
101
|
+
|
102
|
+
|
103
|
+
def _print_framed_text_with_dynamic_line(self, text: str):
|
104
|
+
clear_text = re.sub(r'\u001b\[[0-9;]*m', '', text)
|
105
|
+
max_length_line = max([len(line) for line in clear_text.split('\n')])
|
106
|
+
max_length_line = max_length_line if 10 <= max_length_line <= 80 else 80 if max_length_line > 80 else 10
|
107
|
+
self._print_func(self._dividing_line.get_full_line(max_length_line))
|
108
|
+
print(text.strip('\n'))
|
109
|
+
self._print_func(self._dividing_line.get_full_line(max_length_line))
|
110
|
+
|
111
|
+
|
112
|
+
class AppNonStandardHandlers(AppPrinters):
|
81
113
|
def _is_exit_command(self, command: InputCommand):
|
82
114
|
if command.get_trigger().lower() == self._exit_command.lower():
|
83
115
|
if self._ignore_command_register:
|
@@ -99,53 +131,64 @@ class BaseApp:
|
|
99
131
|
return False
|
100
132
|
if isinstance(self._dividing_line, StaticDividingLine):
|
101
133
|
self._print_func(self._dividing_line.get_full_line())
|
102
|
-
self.
|
134
|
+
self._unknown_command_handler(command)
|
103
135
|
self._print_func(self._dividing_line.get_full_line())
|
104
136
|
elif isinstance(self._dividing_line, DynamicDividingLine):
|
105
137
|
with redirect_stdout(io.StringIO()) as f:
|
106
|
-
self.
|
138
|
+
self._unknown_command_handler(command)
|
107
139
|
res: str = f.getvalue()
|
108
140
|
self._print_framed_text_with_dynamic_line(res)
|
109
141
|
return True
|
110
142
|
|
111
143
|
|
112
|
-
def _print_command_group_description(self):
|
113
|
-
for registered_router in self._registered_routers:
|
114
|
-
self._print_func(registered_router.get_title())
|
115
|
-
for command_handler in registered_router.get_command_handlers():
|
116
|
-
self._print_func(self._description_message_pattern.format(
|
117
|
-
command=command_handler.get_handled_command().get_trigger(),
|
118
|
-
description=command_handler.get_handled_command().get_description()))
|
119
|
-
self._print_func('')
|
120
|
-
|
121
|
-
|
122
144
|
def _error_handler(self, error: BaseInputCommandException, raw_command: str) -> None:
|
123
145
|
match error:
|
124
146
|
case UnprocessedInputFlagException():
|
125
|
-
self.
|
147
|
+
self._invalid_input_flags_handler(raw_command)
|
126
148
|
case RepeatedInputFlagsException():
|
127
|
-
self.
|
149
|
+
self._repeated_input_flags_handler(raw_command)
|
128
150
|
case EmptyInputCommandException():
|
129
|
-
self.
|
151
|
+
self._empty_input_command_handler()
|
130
152
|
|
131
153
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
self._print_func(self._dividing_line.get_full_line(max_length_line))
|
137
|
-
print(text.strip('\n'))
|
138
|
-
self._print_func(self._dividing_line.get_full_line(max_length_line))
|
154
|
+
class AppValidators(AppInit):
|
155
|
+
def _validate_number_of_routers(self) -> None:
|
156
|
+
if not self._registered_routers:
|
157
|
+
raise NoRegisteredRoutersException()
|
139
158
|
|
140
159
|
|
160
|
+
def _validate_included_routers(self) -> None:
|
161
|
+
for router in self._registered_routers:
|
162
|
+
if not router.get_command_handlers():
|
163
|
+
raise NoRegisteredHandlersException(router.get_name())
|
141
164
|
|
142
|
-
|
143
|
-
|
165
|
+
|
166
|
+
class AppSetups(AppValidators, AppPrinters):
|
167
|
+
def _setup_system_router(self):
|
168
|
+
system_router.set_title(self._system_points_title)
|
169
|
+
|
170
|
+
@system_router.command(Command(self._exit_command, self._exit_command_description))
|
171
|
+
def exit_command():
|
172
|
+
self._exit_command_handler()
|
173
|
+
|
174
|
+
if system_router not in self._registered_routers.get_registered_routers():
|
175
|
+
system_router.set_ignore_command_register(self._ignore_command_register)
|
176
|
+
self._registered_routers.add_registered_router(system_router)
|
177
|
+
|
178
|
+
def _setup_default_view(self):
|
179
|
+
if not self._full_override_system_messages:
|
180
|
+
self._initial_message = f'\n[bold red]{text2art(self._initial_message, font='tarty1')}\n\n'
|
181
|
+
self._farewell_message = (
|
182
|
+
f'[bold red]\n{text2art(f'\n{self._farewell_message}\n', font='chanky')}[/bold red]\n'
|
183
|
+
f'[red i]github.com/koloideal/Argenta[/red i] | [red bold i]made by kolo[/red bold i]\n')
|
184
|
+
|
185
|
+
def _pre_cycle_setup(self):
|
186
|
+
self._setup_default_view()
|
144
187
|
self._setup_system_router()
|
145
188
|
self._validate_number_of_routers()
|
146
189
|
self._validate_included_routers()
|
147
190
|
|
148
|
-
self._print_func(self.
|
191
|
+
self._print_func(self._initial_message)
|
149
192
|
|
150
193
|
for message in self._messages_on_startup:
|
151
194
|
self._print_func(message)
|
@@ -153,6 +196,10 @@ class App(BaseApp):
|
|
153
196
|
if not self._repeat_command_groups_description:
|
154
197
|
self._print_command_group_description()
|
155
198
|
|
199
|
+
|
200
|
+
class App(AppSetters, AppNonStandardHandlers, AppSetups):
|
201
|
+
def start_polling(self) -> None:
|
202
|
+
self._pre_cycle_setup()
|
156
203
|
while True:
|
157
204
|
if self._repeat_command_groups_description:
|
158
205
|
self._print_command_group_description()
|
@@ -211,24 +258,3 @@ class App(BaseApp):
|
|
211
258
|
def add_message_on_startup(self, message: str) -> None:
|
212
259
|
self._messages_on_startup.append(message)
|
213
260
|
|
214
|
-
|
215
|
-
def set_description_message_pattern(self, pattern: str) -> None:
|
216
|
-
first_check = re.match(r'.*{command}.*', pattern)
|
217
|
-
second_check = re.match(r'.*{description}.*', pattern)
|
218
|
-
|
219
|
-
if bool(first_check) and bool(second_check):
|
220
|
-
self._description_message_pattern: str = pattern
|
221
|
-
else:
|
222
|
-
raise InvalidDescriptionMessagePatternException(pattern)
|
223
|
-
|
224
|
-
|
225
|
-
def _setup_system_router(self):
|
226
|
-
system_router.set_title(self._system_points_title)
|
227
|
-
@system_router.command(Command(self._exit_command, self._exit_command_description))
|
228
|
-
def exit_command():
|
229
|
-
self.exit_command_handler()
|
230
|
-
|
231
|
-
if system_router not in self._registered_routers.get_registered_routers():
|
232
|
-
self.include_router(system_router)
|
233
|
-
|
234
|
-
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|