argenta 1.0.4__tar.gz → 1.0.6__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-1.0.4 → argenta-1.0.6}/PKG-INFO +2 -3
- argenta-1.0.6/README.de.md +65 -0
- {argenta-1.0.4 → argenta-1.0.6}/README.md +1 -2
- {argenta-1.0.4 → argenta-1.0.6}/README.ru.md +0 -1
- argenta-1.0.6/mock/local_test.py +31 -0
- {argenta-1.0.4 → argenta-1.0.6}/mock/mock_app/main.py +1 -1
- {argenta-1.0.4/mock/mock_app/handlers → argenta-1.0.6/mock/mock_app}/routers.py +4 -2
- {argenta-1.0.4 → argenta-1.0.6}/pyproject.toml +1 -1
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/app/autocompleter/entity.py +1 -1
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/app/defaults.py +2 -2
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/app/models.py +46 -31
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/app/registered_routers/entity.py +1 -1
- argenta-1.0.6/src/argenta/command/flag/__init__.py +7 -0
- {argenta-1.0.4/src/argenta/command → argenta-1.0.6/src/argenta/command/flag}/flags/__init__.py +1 -1
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/command/flag/models.py +1 -1
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/command/models.py +8 -11
- argenta-1.0.6/src/argenta/metrics/__init__.py +4 -0
- argenta-1.0.6/src/argenta/metrics/main.py +26 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/orchestrator/entity.py +2 -2
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/response/entity.py +2 -2
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/router/command_handler/entity.py +1 -1
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/router/entity.py +28 -26
- {argenta-1.0.4 → argenta-1.0.6}/tests/system_tests/test_system_handling_non_standard_behavior.py +1 -1
- {argenta-1.0.4 → argenta-1.0.6}/tests/system_tests/test_system_handling_normal_behavior.py +1 -1
- {argenta-1.0.4 → argenta-1.0.6}/tests/unit_tests/test_command.py +1 -1
- {argenta-1.0.4 → argenta-1.0.6}/tests/unit_tests/test_flag.py +1 -1
- {argenta-1.0.4 → argenta-1.0.6}/tests/unit_tests/test_router.py +1 -1
- argenta-1.0.4/mock/default_mock_app/main.py +0 -27
- argenta-1.0.4/mock/local_test.py +0 -89
- argenta-1.0.4/mock/mock_app/handlers/handlers_implementation/help_command.py +0 -12
- argenta-1.0.4/src/argenta/command/flag/__init__.py +0 -4
- argenta-1.0.4/tests/__init__.py +0 -0
- argenta-1.0.4/tests/system_tests/__init__.py +0 -0
- argenta-1.0.4/tests/unit_tests/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/.github/workflows/ruff.yml +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/.github/workflows/tests.yml +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/.gitignore +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/LICENSE +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/imgs/argenta_banner.png +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/imgs/argenta_logo.png +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/imgs/argenta_logo_strip.png +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/imgs/argenta_logo_strip.svg +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/imgs/mock_app_preview1.png +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/imgs/mock_app_preview2.png +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/imgs/mock_app_preview3.png +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/imgs/mock_app_preview4.png +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/mock/__init__.py +0 -0
- {argenta-1.0.4/mock/default_mock_app → argenta-1.0.6/mock/mock_app}/__init__.py +0 -0
- {argenta-1.0.4/mock/mock_app → argenta-1.0.6/src}/__init__.py +0 -0
- {argenta-1.0.4/mock/mock_app/handlers → argenta-1.0.6/src/argenta}/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/app/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/app/autocompleter/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/app/dividing_line/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/app/dividing_line/models.py +0 -0
- {argenta-1.0.4/mock/mock_app/handlers/handlers_implementation → argenta-1.0.6/src/argenta/app/registered_routers}/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/command/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/command/exceptions.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/command/flag/defaults.py +0 -0
- {argenta-1.0.4/src/argenta/command → argenta-1.0.6/src/argenta/command/flag}/flags/models.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/orchestrator/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/orchestrator/argparser/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/orchestrator/argparser/arguments/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/orchestrator/argparser/arguments/models.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/orchestrator/argparser/entity.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/response/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/response/status.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/router/__init__.py +0 -0
- {argenta-1.0.4/src → argenta-1.0.6/src/argenta/router/command_handler}/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/router/defaults.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/src/argenta/router/exceptions.py +0 -0
- {argenta-1.0.4/src/argenta → argenta-1.0.6/tests}/__init__.py +0 -0
- {argenta-1.0.4/src/argenta/app/registered_routers → argenta-1.0.6/tests/system_tests}/__init__.py +0 -0
- {argenta-1.0.4/src/argenta/router/command_handler → argenta-1.0.6/tests/unit_tests}/__init__.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/tests/unit_tests/test_app.py +0 -0
- {argenta-1.0.4 → argenta-1.0.6}/tests/unit_tests/test_dividing_line.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: argenta
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.6
|
4
4
|
Summary: Python library for building modular CLI applications
|
5
5
|
Author-email: kolo <kolo.is.main@gmail.com>
|
6
6
|
License: MIT
|
@@ -15,7 +15,7 @@ Description-Content-Type: text/markdown
|
|
15
15
|
|
16
16
|
### Library for creating modular CLI applications
|
17
17
|
|
18
|
-
#### RU - [README.ru.md](https://github.com/koloideal/Argenta/blob/kolo/README.ru.md)
|
18
|
+
#### RU - [README.ru.md](https://github.com/koloideal/Argenta/blob/kolo/README.ru.md) • DE - [README.de.md](https://github.com/koloideal/Argenta/blob/kolo/README.de.md)
|
19
19
|
|
20
20
|

|
21
21
|
|
@@ -73,7 +73,6 @@ if __name__ == '__main__':
|
|
73
73
|
# Features in development
|
74
74
|
|
75
75
|
- Full support for autocompleter on Linux
|
76
|
-
- Ability to configure stdout capture when handling input by the handler
|
77
76
|
|
78
77
|
## Full [docs](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
|
79
78
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Argenta
|
2
|
+
|
3
|
+
### Bibliothek zum Erstellen modularer CLI-Anwendungen
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
```bash
|
11
|
+
pip install argenta
|
12
|
+
```
|
13
|
+
or
|
14
|
+
```bash
|
15
|
+
poetry add argenta
|
16
|
+
```
|
17
|
+
|
18
|
+
---
|
19
|
+
|
20
|
+
# Schnellstart
|
21
|
+
|
22
|
+
Ein Beispiel für eine einfache Anwendung
|
23
|
+
```python
|
24
|
+
# routers.py
|
25
|
+
from argenta.router import Router
|
26
|
+
from argenta.command import Command
|
27
|
+
from argenta.response import Response
|
28
|
+
|
29
|
+
|
30
|
+
router = Router()
|
31
|
+
|
32
|
+
@router.command(Command("hello"))
|
33
|
+
def handler(response: Response):
|
34
|
+
print("Hello, world!")
|
35
|
+
```
|
36
|
+
|
37
|
+
```python
|
38
|
+
# main.py
|
39
|
+
from argenta.app import App
|
40
|
+
from argenta.orchestrator import Orchestrator
|
41
|
+
from routers import router
|
42
|
+
|
43
|
+
app: App = App()
|
44
|
+
orchestrator: Orchestrator = Orchestrator()
|
45
|
+
|
46
|
+
|
47
|
+
def main() -> None:
|
48
|
+
app.include_router(router)
|
49
|
+
orchestrator.start_polling(app)
|
50
|
+
|
51
|
+
|
52
|
+
if __name__ == '__main__':
|
53
|
+
main()
|
54
|
+
```
|
55
|
+
|
56
|
+
---
|
57
|
+
|
58
|
+
# Funktionen in der Entwicklung
|
59
|
+
|
60
|
+
- Vollständige Unterstützung für Autocompleter unter Linux
|
61
|
+
|
62
|
+
## Vollständige [Dokumentation](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
|
63
|
+
|
64
|
+
|
65
|
+
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
### Library for creating modular CLI applications
|
4
4
|
|
5
|
-
#### RU - [README.ru.md](https://github.com/koloideal/Argenta/blob/kolo/README.ru.md)
|
5
|
+
#### RU - [README.ru.md](https://github.com/koloideal/Argenta/blob/kolo/README.ru.md) • DE - [README.de.md](https://github.com/koloideal/Argenta/blob/kolo/README.de.md)
|
6
6
|
|
7
7
|

|
8
8
|
|
@@ -60,7 +60,6 @@ if __name__ == '__main__':
|
|
60
60
|
# Features in development
|
61
61
|
|
62
62
|
- Full support for autocompleter on Linux
|
63
|
-
- Ability to configure stdout capture when handling input by the handler
|
64
63
|
|
65
64
|
## Full [docs](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
|
66
65
|
|
@@ -58,7 +58,6 @@ if __name__ == '__main__':
|
|
58
58
|
# Фичи в разработке
|
59
59
|
|
60
60
|
- Полноценная поддержка автокомплитера на Linux
|
61
|
-
- Возможность настройки захвата stdout при обработке хэндлером ввода
|
62
61
|
|
63
62
|
## Полная [документация](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
|
64
63
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
from argenta.router import Router
|
2
|
+
from argenta.command import Command
|
3
|
+
from argenta.response import Response
|
4
|
+
from argenta.metrics import get_time_of_pre_cycle_setup
|
5
|
+
from argenta.response.status import Status
|
6
|
+
from argenta.command.flag import Flag, Flags
|
7
|
+
from argenta.app import App
|
8
|
+
from argenta.orchestrator import Orchestrator
|
9
|
+
|
10
|
+
|
11
|
+
router = Router()
|
12
|
+
|
13
|
+
@router.command(Command('case are'))
|
14
|
+
def handler(response: Response):
|
15
|
+
print(response.status)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
app = App(repeat_command_groups=False)
|
20
|
+
app.include_router(router)
|
21
|
+
|
22
|
+
app.run_polling()
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
@@ -2,12 +2,12 @@ from rich.console import Console
|
|
2
2
|
|
3
3
|
from argenta.command import Command
|
4
4
|
from argenta.command.flag.defaults import PredefinedFlags
|
5
|
-
from argenta.command.
|
5
|
+
from argenta.command.flag import Flags
|
6
6
|
from argenta.response import Response
|
7
7
|
from argenta.router import Router
|
8
8
|
|
9
9
|
|
10
|
-
work_router: Router = Router(title="Work points:")
|
10
|
+
work_router: Router = Router(title="Work points:", disable_redirect_stdout=True)
|
11
11
|
|
12
12
|
console = Console()
|
13
13
|
|
@@ -21,6 +21,8 @@ console = Console()
|
|
21
21
|
)
|
22
22
|
)
|
23
23
|
def command_help(response: Response):
|
24
|
+
case = input('test > ')
|
25
|
+
print(case)
|
24
26
|
print(response.status)
|
25
27
|
print(response.undefined_flags.get_flags())
|
26
28
|
print(response.valid_flags.get_flags())
|
@@ -5,7 +5,7 @@ from typing import Never
|
|
5
5
|
|
6
6
|
class AutoCompleter:
|
7
7
|
def __init__(
|
8
|
-
self, history_filename: str =
|
8
|
+
self, history_filename: str | None = None, autocomplete_button: str = "tab"
|
9
9
|
) -> None:
|
10
10
|
"""
|
11
11
|
Public. Configures and implements auto-completion of input command
|
@@ -201,22 +201,19 @@ class BaseApp:
|
|
201
201
|
return False
|
202
202
|
return True
|
203
203
|
|
204
|
-
def _error_handler(
|
205
|
-
self, error: BaseInputCommandException, raw_command: str
|
206
|
-
) -> None:
|
204
|
+
def _error_handler(self, error: BaseInputCommandException, raw_command: str) -> None:
|
207
205
|
"""
|
208
206
|
Private. Handles parsing errors of the entered command
|
209
207
|
:param error: error being handled
|
210
208
|
:param raw_command: the raw input command
|
211
209
|
:return: None
|
212
210
|
"""
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
self._empty_input_command_handler()
|
211
|
+
if isinstance(error, UnprocessedInputFlagException):
|
212
|
+
self._incorrect_input_syntax_handler(raw_command)
|
213
|
+
elif isinstance(error, RepeatedInputFlagsException):
|
214
|
+
self._repeated_input_flags_handler(raw_command)
|
215
|
+
elif isinstance(error, EmptyInputCommandException):
|
216
|
+
self._empty_input_command_handler()
|
220
217
|
|
221
218
|
def _setup_system_router(self) -> None:
|
222
219
|
"""
|
@@ -260,11 +257,11 @@ class BaseApp:
|
|
260
257
|
"""
|
261
258
|
self._prompt = "[italic dim bold]What do you want to do?\n"
|
262
259
|
self._initial_message = (
|
263
|
-
|
260
|
+
"\n"+f"[bold red]{text2art(self._initial_message, font='tarty1')}"+"\n"
|
264
261
|
)
|
265
262
|
self._farewell_message = (
|
266
|
-
|
267
|
-
|
263
|
+
"[bold red]\n\n"+text2art(self._farewell_message, font='chanky')+"\n[/bold red]\n"
|
264
|
+
"[red i]github.com/koloideal/Argenta[/red i] | [red bold i]made by kolo[/red bold i]\n"
|
268
265
|
)
|
269
266
|
self._description_message_gen = lambda command, description: (
|
270
267
|
f"[bold red]{escape('[' + command + ']')}[/bold red] "
|
@@ -296,7 +293,7 @@ class BaseApp:
|
|
296
293
|
|
297
294
|
self._unknown_command_handler = unknown_command_handler
|
298
295
|
|
299
|
-
def
|
296
|
+
def pre_cycle_setup(self) -> None:
|
300
297
|
"""
|
301
298
|
Private. Configures various aspects of the application before the start of the cycle
|
302
299
|
:return: None
|
@@ -304,22 +301,30 @@ class BaseApp:
|
|
304
301
|
self._setup_system_router()
|
305
302
|
|
306
303
|
for router_entity in self._registered_routers:
|
307
|
-
|
308
|
-
|
304
|
+
router_triggers = router_entity.get_triggers()
|
305
|
+
router_aliases = router_entity.get_aliases()
|
306
|
+
combined = router_triggers + router_aliases
|
309
307
|
|
310
|
-
self.
|
311
|
-
|
308
|
+
self._all_registered_triggers_in_default_case.extend(combined)
|
309
|
+
|
310
|
+
self._all_registered_triggers_in_lower_case.extend(x.lower() for x in combined)
|
312
311
|
|
313
312
|
self._autocompleter.initial_setup(self._all_registered_triggers_in_lower_case)
|
314
313
|
|
315
314
|
if self._ignore_command_register:
|
316
|
-
|
317
|
-
|
318
|
-
|
315
|
+
seen = {}
|
316
|
+
for item in self._all_registered_triggers_in_lower_case:
|
317
|
+
if item in seen:
|
318
|
+
Console().print(f"\n[b red]WARNING:[/b red] Overlapping trigger or alias: [b blue]{item}[/b blue]")
|
319
|
+
else:
|
320
|
+
seen[item] = True
|
319
321
|
else:
|
320
|
-
|
321
|
-
|
322
|
-
|
322
|
+
seen = {}
|
323
|
+
for item in self._all_registered_triggers_in_default_case:
|
324
|
+
if item in seen:
|
325
|
+
Console().print(f"\n[b red]WARNING:[/b red] Overlapping trigger or alias: [b blue]{item}[/b blue]")
|
326
|
+
else:
|
327
|
+
seen[item] = True
|
323
328
|
|
324
329
|
if not self._override_system_messages:
|
325
330
|
self._setup_default_view()
|
@@ -330,7 +335,6 @@ class BaseApp:
|
|
330
335
|
self._print_func(message)
|
331
336
|
if self._messages_on_startup:
|
332
337
|
print("\n")
|
333
|
-
|
334
338
|
if not self._repeat_command_groups_description:
|
335
339
|
self._print_command_group_description()
|
336
340
|
|
@@ -381,7 +385,7 @@ class App(BaseApp):
|
|
381
385
|
Private. Starts the user input processing cycle
|
382
386
|
:return: None
|
383
387
|
"""
|
384
|
-
self.
|
388
|
+
self.pre_cycle_setup()
|
385
389
|
while True:
|
386
390
|
if self._repeat_command_groups_description:
|
387
391
|
self._print_command_group_description()
|
@@ -418,11 +422,22 @@ class App(BaseApp):
|
|
418
422
|
self._print_framed_text(res)
|
419
423
|
continue
|
420
424
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
425
|
+
for registered_router in self._registered_routers:
|
426
|
+
if registered_router.disable_redirect_stdout:
|
427
|
+
if isinstance(self._dividing_line, StaticDividingLine):
|
428
|
+
self._print_func(self._dividing_line.get_full_static_line(self._override_system_messages))
|
429
|
+
registered_router.finds_appropriate_handler(input_command)
|
430
|
+
self._print_func(self._dividing_line.get_full_static_line(self._override_system_messages))
|
431
|
+
else:
|
432
|
+
self._print_func(StaticDividingLine(self._dividing_line.get_unit_part()).get_full_static_line(self._override_system_messages))
|
433
|
+
registered_router.finds_appropriate_handler(input_command)
|
434
|
+
self._print_func(StaticDividingLine(self._dividing_line.get_unit_part()).get_full_static_line(self._override_system_messages))
|
435
|
+
else:
|
436
|
+
with redirect_stdout(io.StringIO()) as f:
|
437
|
+
registered_router.finds_appropriate_handler(input_command)
|
438
|
+
res: str = f.getvalue()
|
439
|
+
if res:
|
440
|
+
self._print_framed_text(res)
|
426
441
|
|
427
442
|
def include_router(self, router: Router) -> None:
|
428
443
|
"""
|
@@ -4,7 +4,7 @@ from argenta.router import Router
|
|
4
4
|
|
5
5
|
|
6
6
|
class RegisteredRouters:
|
7
|
-
def __init__(self, registered_routers: list[Router] = None) -> None:
|
7
|
+
def __init__(self, registered_routers: list[Router] | None = None) -> None:
|
8
8
|
"""
|
9
9
|
Private. Combines registered routers
|
10
10
|
:param registered_routers: list of the registered routers
|
@@ -0,0 +1,7 @@
|
|
1
|
+
__all__ = ["Flag", "InputFlag", "UndefinedInputFlags", "ValidInputFlags", "InvalidValueInputFlags", "Flags"]
|
2
|
+
|
3
|
+
|
4
|
+
from argenta.command.flag.models import Flag, InputFlag
|
5
|
+
from argenta.command.flag.flags.models import (UndefinedInputFlags,
|
6
|
+
ValidInputFlags, Flags,
|
7
|
+
InvalidValueInputFlags)
|
@@ -87,7 +87,7 @@ class Flag(BaseFlag):
|
|
87
87
|
|
88
88
|
class InputFlag(BaseFlag):
|
89
89
|
def __init__(
|
90
|
-
self, name: str, prefix: Literal["-", "--", "---"] = "--", value: str = None
|
90
|
+
self, name: str, prefix: Literal["-", "--", "---"] = "--", value: str | None = None
|
91
91
|
):
|
92
92
|
"""
|
93
93
|
Public. The entity of the flag of the entered command
|
@@ -1,14 +1,11 @@
|
|
1
1
|
from argenta.command.flag.models import Flag, InputFlag
|
2
|
-
from argenta.command.flags.models import InputFlags, Flags
|
2
|
+
from argenta.command.flag.flags.models import InputFlags, Flags
|
3
3
|
from argenta.command.exceptions import (
|
4
4
|
UnprocessedInputFlagException,
|
5
5
|
RepeatedInputFlagsException,
|
6
6
|
EmptyInputCommandException,
|
7
7
|
)
|
8
|
-
from typing import
|
9
|
-
|
10
|
-
|
11
|
-
InputCommandType = TypeVar("InputCommandType")
|
8
|
+
from typing import cast, Literal
|
12
9
|
|
13
10
|
|
14
11
|
class BaseCommand:
|
@@ -31,9 +28,9 @@ class Command(BaseCommand):
|
|
31
28
|
def __init__(
|
32
29
|
self,
|
33
30
|
trigger: str,
|
34
|
-
description: str = None,
|
35
|
-
flags: Flag | Flags = None,
|
36
|
-
aliases: list[str] = None,
|
31
|
+
description: str | None = None,
|
32
|
+
flags: Flag | Flags | None = None,
|
33
|
+
aliases: list[str] | None = None,
|
37
34
|
):
|
38
35
|
"""
|
39
36
|
Public. The command that can and should be registered in the Router
|
@@ -109,8 +106,8 @@ class Command(BaseCommand):
|
|
109
106
|
return self._description
|
110
107
|
|
111
108
|
|
112
|
-
class InputCommand(BaseCommand
|
113
|
-
def __init__(self, trigger: str, input_flags: InputFlag | InputFlags = None):
|
109
|
+
class InputCommand(BaseCommand):
|
110
|
+
def __init__(self, trigger: str, input_flags: InputFlag | InputFlags | None = None):
|
114
111
|
"""
|
115
112
|
Private. The model of the input command, after parsing
|
116
113
|
:param trigger:the trigger of the command
|
@@ -142,7 +139,7 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
|
|
142
139
|
return self._input_flags
|
143
140
|
|
144
141
|
@staticmethod
|
145
|
-
def parse(raw_command: str) ->
|
142
|
+
def parse(raw_command: str) -> 'InputCommand':
|
146
143
|
"""
|
147
144
|
Private. Parse the raw input command
|
148
145
|
:param raw_command: raw input command
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import io
|
2
|
+
from contextlib import redirect_stdout
|
3
|
+
from time import time
|
4
|
+
|
5
|
+
from argenta.app import App
|
6
|
+
|
7
|
+
|
8
|
+
def get_time_of_pre_cycle_setup(app: App) -> float:
|
9
|
+
"""
|
10
|
+
Public. Return time of pre cycle setup
|
11
|
+
:param app: app instance for testing time of pre cycle setup
|
12
|
+
:return: time of pre cycle setup as float
|
13
|
+
"""
|
14
|
+
start = time()
|
15
|
+
with redirect_stdout(io.StringIO()):
|
16
|
+
app.pre_cycle_setup()
|
17
|
+
end = time()
|
18
|
+
return end - start
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
@@ -5,13 +5,13 @@ from argenta.orchestrator.argparser import ArgParser
|
|
5
5
|
|
6
6
|
|
7
7
|
class Orchestrator:
|
8
|
-
def __init__(self, arg_parser: ArgParser =
|
8
|
+
def __init__(self, arg_parser: ArgParser | None = None):
|
9
9
|
"""
|
10
10
|
Public. An orchestrator and configurator that defines the behavior of an integrated system, one level higher than the App
|
11
11
|
:param arg_parser: Cmd argument parser and configurator at startup
|
12
12
|
:return: None
|
13
13
|
"""
|
14
|
-
self.arg_parser: ArgParser |
|
14
|
+
self.arg_parser: ArgParser | None = arg_parser
|
15
15
|
if arg_parser:
|
16
16
|
self.arg_parser.register_args()
|
17
17
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from argenta.response.status import Status
|
2
|
-
from argenta.command.flags import (
|
2
|
+
from argenta.command.flag.flags import (
|
3
3
|
ValidInputFlags,
|
4
4
|
UndefinedInputFlags,
|
5
5
|
InvalidValueInputFlags,
|
@@ -11,7 +11,7 @@ class Response:
|
|
11
11
|
|
12
12
|
def __init__(
|
13
13
|
self,
|
14
|
-
status: Status = None,
|
14
|
+
status: Status | None = None,
|
15
15
|
valid_flags: ValidInputFlags = ValidInputFlags(),
|
16
16
|
undefined_flags: UndefinedInputFlags = UndefinedInputFlags(),
|
17
17
|
invalid_value_flags: InvalidValueInputFlags = InvalidValueInputFlags(),
|
@@ -38,7 +38,7 @@ class CommandHandler:
|
|
38
38
|
|
39
39
|
|
40
40
|
class CommandHandlers:
|
41
|
-
def __init__(self, command_handlers: list[CommandHandler] = None):
|
41
|
+
def __init__(self, command_handlers: list[CommandHandler] | None = None):
|
42
42
|
"""
|
43
43
|
Private. The model that unites all CommandHandler of the routers
|
44
44
|
:param command_handlers: list of CommandHandlers for register
|
@@ -6,7 +6,7 @@ from argenta.command import Command
|
|
6
6
|
from argenta.command.models import InputCommand
|
7
7
|
from argenta.response import Response, Status
|
8
8
|
from argenta.router.command_handler.entity import CommandHandlers, CommandHandler
|
9
|
-
from argenta.command.flags
|
9
|
+
from argenta.command.flag.flags import (
|
10
10
|
Flags,
|
11
11
|
InputFlags,
|
12
12
|
UndefinedInputFlags,
|
@@ -22,13 +22,19 @@ from argenta.router.exceptions import (
|
|
22
22
|
|
23
23
|
|
24
24
|
class Router:
|
25
|
-
def __init__(self, title: str | None = "Awesome title"):
|
25
|
+
def __init__(self, title: str | None = "Awesome title", disable_redirect_stdout: bool = False):
|
26
26
|
"""
|
27
27
|
Public. Directly configures and manages handlers
|
28
28
|
:param title: the title of the router, displayed when displaying the available commands
|
29
|
+
:param disable_redirect_stdout: Disables stdout forwarding, if the argument value is True,
|
30
|
+
the StaticDividingLine will be forced to be used as a line separator for this router,
|
31
|
+
disabled forwarding is needed when there is text output in conjunction with a text input request (for example, input()),
|
32
|
+
if the argument value is True, the output of the input() prompt is intercepted and not displayed,
|
33
|
+
which is ambiguous behavior and can lead to unexpected work
|
29
34
|
:return: None
|
30
35
|
"""
|
31
36
|
self.title = title
|
37
|
+
self.disable_redirect_stdout = disable_redirect_stdout
|
32
38
|
|
33
39
|
self._command_handlers: CommandHandlers = CommandHandlers()
|
34
40
|
self._ignore_command_register: bool = False
|
@@ -39,13 +45,15 @@ class Router:
|
|
39
45
|
:param command: Registered command
|
40
46
|
:return: decorated handler as Callable
|
41
47
|
"""
|
42
|
-
self._validate_command(command)
|
43
48
|
if isinstance(command, str):
|
44
|
-
|
49
|
+
redefined_command = Command(command)
|
50
|
+
else:
|
51
|
+
redefined_command = command
|
52
|
+
self._validate_command(redefined_command)
|
45
53
|
|
46
54
|
def command_decorator(func):
|
47
55
|
Router._validate_func_args(func)
|
48
|
-
self._command_handlers.add_handler(CommandHandler(func,
|
56
|
+
self._command_handlers.add_handler(CommandHandler(func, redefined_command))
|
49
57
|
|
50
58
|
def wrapper(*args, **kwargs):
|
51
59
|
return func(*args, **kwargs)
|
@@ -117,13 +125,12 @@ class Router:
|
|
117
125
|
flag_status: Literal["Undefined", "Valid", "Invalid"] = (
|
118
126
|
handled_command.validate_input_flag(flag)
|
119
127
|
)
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
invalid_value_input_flags.add_flag(flag)
|
128
|
+
if flag_status == "Valid":
|
129
|
+
valid_input_flags.add_flag(flag)
|
130
|
+
elif flag_status == "Undefined":
|
131
|
+
undefined_input_flags.add_flag(flag)
|
132
|
+
elif flag_status == "Invalid":
|
133
|
+
invalid_value_input_flags.add_flag(flag)
|
127
134
|
|
128
135
|
if (
|
129
136
|
not invalid_value_input_flags.get_flags()
|
@@ -157,19 +164,14 @@ class Router:
|
|
157
164
|
:param command: validated command
|
158
165
|
:return: None if command is valid else raise exception
|
159
166
|
"""
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
if len(set(flags_name)) < len(flags_name):
|
169
|
-
raise RepeatedFlagNameException()
|
170
|
-
case "str":
|
171
|
-
if command.find(" ") != -1:
|
172
|
-
raise TriggerContainSpacesException()
|
167
|
+
command_name: str = command.get_trigger()
|
168
|
+
if command_name.find(" ") != -1:
|
169
|
+
raise TriggerContainSpacesException()
|
170
|
+
flags: Flags = command.get_registered_flags()
|
171
|
+
if flags:
|
172
|
+
flags_name: list = [x.get_string_entity().lower() for x in flags]
|
173
|
+
if len(set(flags_name)) < len(flags_name):
|
174
|
+
raise RepeatedFlagNameException()
|
173
175
|
|
174
176
|
@staticmethod
|
175
177
|
def _validate_func_args(func: Callable) -> None:
|
@@ -191,7 +193,7 @@ class Router:
|
|
191
193
|
if arg_annotation is Response:
|
192
194
|
pass
|
193
195
|
else:
|
194
|
-
file_path: str = getsourcefile(func)
|
196
|
+
file_path: str | None = getsourcefile(func)
|
195
197
|
source_line: int = getsourcelines(func)[1]
|
196
198
|
fprint = Console().print
|
197
199
|
fprint(f'\nFile "{file_path}", line {source_line}\n[b red]WARNING:[/b red] [i]The typehint '
|
{argenta-1.0.4 → argenta-1.0.6}/tests/system_tests/test_system_handling_non_standard_behavior.py
RENAMED
@@ -7,7 +7,7 @@ import re
|
|
7
7
|
from argenta.app import App
|
8
8
|
from argenta.command import Command
|
9
9
|
from argenta.router import Router
|
10
|
-
from argenta.command.flags.models import Flags
|
10
|
+
from argenta.command.flag.flags.models import Flags
|
11
11
|
from argenta.command.flag.defaults import PredefinedFlags
|
12
12
|
from argenta.orchestrator import Orchestrator
|
13
13
|
from argenta.response import Response
|
@@ -10,7 +10,7 @@ from argenta.response import Response
|
|
10
10
|
from argenta.router import Router
|
11
11
|
from argenta.orchestrator import Orchestrator
|
12
12
|
from argenta.command.flag import Flag
|
13
|
-
from argenta.command.flags import Flags
|
13
|
+
from argenta.command.flag.flags import Flags
|
14
14
|
from argenta.command.flag.defaults import PredefinedFlags
|
15
15
|
|
16
16
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from argenta.command.flag import Flag, InputFlag
|
2
|
-
from argenta.command.flags import Flags
|
2
|
+
from argenta.command.flag.flags import Flags
|
3
3
|
from argenta.command.models import InputCommand, Command
|
4
4
|
from argenta.command.exceptions import (UnprocessedInputFlagException,
|
5
5
|
RepeatedInputFlagsException,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from argenta.command.flag import InputFlag, Flag
|
2
|
-
from argenta.command.flags import Flags, InputFlags, UndefinedInputFlags, InvalidValueInputFlags, ValidInputFlags
|
2
|
+
from argenta.command.flag.flags import Flags, InputFlags, UndefinedInputFlags, InvalidValueInputFlags, ValidInputFlags
|
3
3
|
from argenta.router import Router
|
4
4
|
from argenta.command import Command
|
5
5
|
from argenta.router.exceptions import (TriggerContainSpacesException,
|
@@ -1,27 +0,0 @@
|
|
1
|
-
from mock.mock_app.handlers.routers import work_router
|
2
|
-
|
3
|
-
from argenta.app import App
|
4
|
-
from argenta.app.defaults import PredefinedMessages
|
5
|
-
from argenta.app.autocompleter import AutoCompleter
|
6
|
-
from argenta.orchestrator import Orchestrator
|
7
|
-
from argenta.orchestrator.argparser import ArgParser
|
8
|
-
from argenta.orchestrator.argparser.arguments import BooleanArgument
|
9
|
-
|
10
|
-
|
11
|
-
arg_parser = ArgParser(processed_args=[BooleanArgument("repeat")])
|
12
|
-
app: App = App(autocompleter=AutoCompleter(".hist"))
|
13
|
-
orchestrator: Orchestrator = Orchestrator()
|
14
|
-
|
15
|
-
|
16
|
-
def main():
|
17
|
-
app.include_router(work_router)
|
18
|
-
|
19
|
-
app.add_message_on_startup(PredefinedMessages.USAGE)
|
20
|
-
app.add_message_on_startup(PredefinedMessages.AUTOCOMPLETE)
|
21
|
-
app.add_message_on_startup(PredefinedMessages.HELP)
|
22
|
-
|
23
|
-
orchestrator.start_polling(app)
|
24
|
-
|
25
|
-
|
26
|
-
if __name__ == "__main__":
|
27
|
-
main()
|
argenta-1.0.4/mock/local_test.py
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
from argenta.router import Router
|
2
|
-
from argenta.command import Command
|
3
|
-
from argenta.response import Response
|
4
|
-
from argenta.response.status import Status
|
5
|
-
from argenta.command.flag import Flag
|
6
|
-
from argenta.command.flags import Flags
|
7
|
-
from argenta.app import App
|
8
|
-
from argenta.orchestrator import Orchestrator
|
9
|
-
|
10
|
-
# Создание маршрутизатора
|
11
|
-
file_router = Router("Операции с файлами")
|
12
|
-
|
13
|
-
# Определение флагов для команды копирования
|
14
|
-
copy_flags = Flags(
|
15
|
-
Flag('source', '--'),
|
16
|
-
Flag('destination', '--'),
|
17
|
-
Flag('recursive', '--', False), # Булевый флаг без значения
|
18
|
-
Flag('force', '-', False) # Короткий булевый флаг
|
19
|
-
)
|
20
|
-
@file_router.command(Command('case', aliases=['cp', 'ch']))
|
21
|
-
def handler(response: Response):
|
22
|
-
print('test')
|
23
|
-
|
24
|
-
# Регистрация команды копирования
|
25
|
-
@file_router.command(Command(
|
26
|
-
trigger="ch",
|
27
|
-
description="Копирование файлов",
|
28
|
-
flags=copy_flags,
|
29
|
-
aliases=["cp"]
|
30
|
-
))
|
31
|
-
def copy_files(response: Response):
|
32
|
-
# Получаем значения корректных флагов
|
33
|
-
source = None
|
34
|
-
destination = None
|
35
|
-
recursive = False
|
36
|
-
force = False
|
37
|
-
|
38
|
-
for flag in response.valid_flags:
|
39
|
-
if flag.get_name() == "source":
|
40
|
-
source = flag.get_value()
|
41
|
-
elif flag.get_name() == "destination":
|
42
|
-
destination = flag.get_value()
|
43
|
-
elif flag.get_name() == "recursive":
|
44
|
-
recursive = True
|
45
|
-
elif flag.get_name() == "force":
|
46
|
-
force = True
|
47
|
-
|
48
|
-
# Проверка обязательных параметров
|
49
|
-
if not source or not destination:
|
50
|
-
print("Ошибка: необходимо указать источник и назначение")
|
51
|
-
return
|
52
|
-
|
53
|
-
print(f"Копирование из {source} в {destination}")
|
54
|
-
if recursive:
|
55
|
-
print("Рекурсивное копирование включено")
|
56
|
-
if force:
|
57
|
-
print("Принудительное копирование включено")
|
58
|
-
|
59
|
-
# Обработка неопределенных флагов
|
60
|
-
if response.undefined_flags:
|
61
|
-
print("\nПредупреждение: обнаружены незарегистрированные флаги:")
|
62
|
-
for flag in response.undefined_flags:
|
63
|
-
print(f" - {flag.get_name()}" +
|
64
|
-
(f" = {flag.get_value()}" if flag.get_value() else ""))
|
65
|
-
|
66
|
-
# Обработка флагов с некорректными значениями
|
67
|
-
if response.invalid_value_flags:
|
68
|
-
print("\nПредупреждение: обнаружены флаги с некорректными значениями:")
|
69
|
-
for flag in response.invalid_value_flags:
|
70
|
-
print(f" - {flag.get_name()} = {flag.get_value()}")
|
71
|
-
|
72
|
-
# Принятие решения на основе статуса
|
73
|
-
if response.status != Status.ALL_FLAGS_VALID:
|
74
|
-
print("\nВыполнение с предупреждениями из-за проблем с флагами.")
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
app = App()
|
79
|
-
app.include_router(file_router)
|
80
|
-
orchestrator = Orchestrator()
|
81
|
-
|
82
|
-
orchestrator.start_polling(app)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
@@ -1,12 +0,0 @@
|
|
1
|
-
from rich.console import Console
|
2
|
-
|
3
|
-
|
4
|
-
console = Console()
|
5
|
-
|
6
|
-
|
7
|
-
def help_command():
|
8
|
-
console.print(
|
9
|
-
"[italic bold]The main functionality of the script is to convert an expression from a string "
|
10
|
-
"to a mathematical one and then calculate this expression. "
|
11
|
-
"Project GitHub: https://github.com/koloideal/WordMath[/italic bold]"
|
12
|
-
)
|
argenta-1.0.4/tests/__init__.py
DELETED
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{argenta-1.0.4/src/argenta/command → argenta-1.0.6/src/argenta/command/flag}/flags/models.py
RENAMED
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
|
{argenta-1.0.4/src/argenta/app/registered_routers → argenta-1.0.6/tests/system_tests}/__init__.py
RENAMED
File without changes
|
{argenta-1.0.4/src/argenta/router/command_handler → argenta-1.0.6/tests/unit_tests}/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|