argenta 1.0.2__tar.gz → 1.0.4__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.
Files changed (71) hide show
  1. {argenta-1.0.2 → argenta-1.0.4}/PKG-INFO +16 -6
  2. argenta-1.0.4/README.md +68 -0
  3. argenta-1.0.2/README.md → argenta-1.0.4/README.ru.md +8 -0
  4. argenta-1.0.4/mock/local_test.py +89 -0
  5. {argenta-1.0.2 → argenta-1.0.4}/pyproject.toml +1 -1
  6. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/app/defaults.py +2 -4
  7. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/app/models.py +59 -76
  8. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/router/entity.py +4 -6
  9. {argenta-1.0.2 → argenta-1.0.4}/tests/unit_tests/test_app.py +2 -2
  10. argenta-1.0.2/mock/local_test.py +0 -89
  11. {argenta-1.0.2 → argenta-1.0.4}/.github/workflows/ruff.yml +0 -0
  12. {argenta-1.0.2 → argenta-1.0.4}/.github/workflows/tests.yml +0 -0
  13. {argenta-1.0.2 → argenta-1.0.4}/.gitignore +0 -0
  14. {argenta-1.0.2 → argenta-1.0.4}/LICENSE +0 -0
  15. {argenta-1.0.2 → argenta-1.0.4}/imgs/argenta_banner.png +0 -0
  16. {argenta-1.0.2 → argenta-1.0.4}/imgs/argenta_logo.png +0 -0
  17. {argenta-1.0.2 → argenta-1.0.4}/imgs/argenta_logo_strip.png +0 -0
  18. {argenta-1.0.2 → argenta-1.0.4}/imgs/argenta_logo_strip.svg +0 -0
  19. {argenta-1.0.2 → argenta-1.0.4}/imgs/mock_app_preview1.png +0 -0
  20. {argenta-1.0.2 → argenta-1.0.4}/imgs/mock_app_preview2.png +0 -0
  21. {argenta-1.0.2 → argenta-1.0.4}/imgs/mock_app_preview3.png +0 -0
  22. {argenta-1.0.2 → argenta-1.0.4}/imgs/mock_app_preview4.png +0 -0
  23. {argenta-1.0.2 → argenta-1.0.4}/mock/__init__.py +0 -0
  24. {argenta-1.0.2 → argenta-1.0.4}/mock/default_mock_app/__init__.py +0 -0
  25. {argenta-1.0.2 → argenta-1.0.4}/mock/default_mock_app/main.py +0 -0
  26. {argenta-1.0.2 → argenta-1.0.4}/mock/mock_app/__init__.py +0 -0
  27. {argenta-1.0.2 → argenta-1.0.4}/mock/mock_app/handlers/__init__.py +0 -0
  28. {argenta-1.0.2 → argenta-1.0.4}/mock/mock_app/handlers/handlers_implementation/__init__.py +0 -0
  29. {argenta-1.0.2 → argenta-1.0.4}/mock/mock_app/handlers/handlers_implementation/help_command.py +0 -0
  30. {argenta-1.0.2 → argenta-1.0.4}/mock/mock_app/handlers/routers.py +0 -0
  31. {argenta-1.0.2 → argenta-1.0.4}/mock/mock_app/main.py +0 -0
  32. {argenta-1.0.2 → argenta-1.0.4}/src/__init__.py +0 -0
  33. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/__init__.py +0 -0
  34. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/app/__init__.py +0 -0
  35. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/app/autocompleter/__init__.py +0 -0
  36. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/app/autocompleter/entity.py +0 -0
  37. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/app/dividing_line/__init__.py +0 -0
  38. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/app/dividing_line/models.py +0 -0
  39. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/app/registered_routers/__init__.py +0 -0
  40. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/app/registered_routers/entity.py +0 -0
  41. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/command/__init__.py +0 -0
  42. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/command/exceptions.py +0 -0
  43. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/command/flag/__init__.py +0 -0
  44. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/command/flag/defaults.py +0 -0
  45. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/command/flag/models.py +0 -0
  46. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/command/flags/__init__.py +0 -0
  47. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/command/flags/models.py +0 -0
  48. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/command/models.py +0 -0
  49. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/orchestrator/__init__.py +0 -0
  50. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/orchestrator/argparser/__init__.py +0 -0
  51. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/orchestrator/argparser/arguments/__init__.py +0 -0
  52. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/orchestrator/argparser/arguments/models.py +0 -0
  53. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/orchestrator/argparser/entity.py +0 -0
  54. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/orchestrator/entity.py +0 -0
  55. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/response/__init__.py +0 -0
  56. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/response/entity.py +0 -0
  57. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/response/status.py +0 -0
  58. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/router/__init__.py +0 -0
  59. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/router/command_handler/__init__.py +0 -0
  60. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/router/command_handler/entity.py +0 -0
  61. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/router/defaults.py +0 -0
  62. {argenta-1.0.2 → argenta-1.0.4}/src/argenta/router/exceptions.py +0 -0
  63. {argenta-1.0.2 → argenta-1.0.4}/tests/__init__.py +0 -0
  64. {argenta-1.0.2 → argenta-1.0.4}/tests/system_tests/__init__.py +0 -0
  65. {argenta-1.0.2 → argenta-1.0.4}/tests/system_tests/test_system_handling_non_standard_behavior.py +0 -0
  66. {argenta-1.0.2 → argenta-1.0.4}/tests/system_tests/test_system_handling_normal_behavior.py +0 -0
  67. {argenta-1.0.2 → argenta-1.0.4}/tests/unit_tests/__init__.py +0 -0
  68. {argenta-1.0.2 → argenta-1.0.4}/tests/unit_tests/test_command.py +0 -0
  69. {argenta-1.0.2 → argenta-1.0.4}/tests/unit_tests/test_dividing_line.py +0 -0
  70. {argenta-1.0.2 → argenta-1.0.4}/tests/unit_tests/test_flag.py +0 -0
  71. {argenta-1.0.2 → argenta-1.0.4}/tests/unit_tests/test_router.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: argenta
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: Python library for building modular CLI applications
5
5
  Author-email: kolo <kolo.is.main@gmail.com>
6
6
  License: MIT
@@ -13,13 +13,15 @@ Description-Content-Type: text/markdown
13
13
 
14
14
  # Argenta
15
15
 
16
- ### Библиотека для создания модульных CLI приложeний
16
+ ### Library for creating modular CLI applications
17
+
18
+ #### RU - [README.ru.md](https://github.com/koloideal/Argenta/blob/kolo/README.ru.md)
17
19
 
18
20
  ![preview](https://github.com/koloideal/Argenta/blob/kolo/imgs/mock_app_preview4.png?raw=True)
19
21
 
20
22
  ---
21
23
 
22
- # Установка
24
+ # Installing
23
25
  ```bash
24
26
  pip install argenta
25
27
  ```
@@ -30,9 +32,9 @@ poetry add argenta
30
32
 
31
33
  ---
32
34
 
33
- # Быстрый старт
35
+ # Quick start
34
36
 
35
- Пример простейшего приложения
37
+ An example of a simple application
36
38
  ```python
37
39
  # routers.py
38
40
  from argenta.router import Router
@@ -65,7 +67,15 @@ def main() -> None:
65
67
  if __name__ == '__main__':
66
68
  main()
67
69
  ```
68
- ## Полная [документация](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
70
+
71
+ ---
72
+
73
+ # Features in development
74
+
75
+ - Full support for autocompleter on Linux
76
+ - Ability to configure stdout capture when handling input by the handler
77
+
78
+ ## Full [docs](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
69
79
 
70
80
 
71
81
 
@@ -0,0 +1,68 @@
1
+ # Argenta
2
+
3
+ ### Library for creating modular CLI applications
4
+
5
+ #### RU - [README.ru.md](https://github.com/koloideal/Argenta/blob/kolo/README.ru.md)
6
+
7
+ ![preview](https://github.com/koloideal/Argenta/blob/kolo/imgs/mock_app_preview4.png?raw=True)
8
+
9
+ ---
10
+
11
+ # Installing
12
+ ```bash
13
+ pip install argenta
14
+ ```
15
+ or
16
+ ```bash
17
+ poetry add argenta
18
+ ```
19
+
20
+ ---
21
+
22
+ # Quick start
23
+
24
+ An example of a simple application
25
+ ```python
26
+ # routers.py
27
+ from argenta.router import Router
28
+ from argenta.command import Command
29
+ from argenta.response import Response
30
+
31
+
32
+ router = Router()
33
+
34
+ @router.command(Command("hello"))
35
+ def handler(response: Response):
36
+ print("Hello, world!")
37
+ ```
38
+
39
+ ```python
40
+ # main.py
41
+ from argenta.app import App
42
+ from argenta.orchestrator import Orchestrator
43
+ from routers import router
44
+
45
+ app: App = App()
46
+ orchestrator: Orchestrator = Orchestrator()
47
+
48
+
49
+ def main() -> None:
50
+ app.include_router(router)
51
+ orchestrator.start_polling(app)
52
+
53
+
54
+ if __name__ == '__main__':
55
+ main()
56
+ ```
57
+
58
+ ---
59
+
60
+ # Features in development
61
+
62
+ - Full support for autocompleter on Linux
63
+ - Ability to configure stdout capture when handling input by the handler
64
+
65
+ ## Full [docs](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
66
+
67
+
68
+
@@ -52,6 +52,14 @@ def main() -> None:
52
52
  if __name__ == '__main__':
53
53
  main()
54
54
  ```
55
+
56
+ ---
57
+
58
+ # Фичи в разработке
59
+
60
+ - Полноценная поддержка автокомплитера на Linux
61
+ - Возможность настройки захвата stdout при обработке хэндлером ввода
62
+
55
63
  ## Полная [документация](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
56
64
 
57
65
 
@@ -0,0 +1,89 @@
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,6 +1,6 @@
1
1
  [project]
2
2
  name = "argenta"
3
- version = "1.0.2"
3
+ version = "1.0.4"
4
4
  description = "Python library for building modular CLI applications"
5
5
  authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }]
6
6
  requires-python = ">=3.8"
@@ -1,12 +1,10 @@
1
- from dataclasses import dataclass
1
+ from enum import Enum
2
2
 
3
3
 
4
- @dataclass
5
- class PredefinedMessages:
4
+ class PredefinedMessages(Enum):
6
5
  """
7
6
  Public. A dataclass with predetermined messages for quick use
8
7
  """
9
-
10
8
  USAGE = "[b dim]Usage[/b dim]: [i]<command> <[green]flags[/green]>[/i]"
11
9
  HELP = "[b dim]Help[/b dim]: [i]<command>[/i] [b red]--help[/b red]"
12
10
  AUTOCOMPLETE = "[b dim]Autocomplete[/b dim]: [i]<part>[/i] [bold]<tab>"
@@ -22,20 +22,18 @@ from argenta.response import Response
22
22
 
23
23
 
24
24
  class BaseApp:
25
- def __init__(
26
- self,
27
- prompt: str,
28
- initial_message: str,
29
- farewell_message: str,
30
- exit_command: Command,
31
- system_router_title: str | None,
32
- ignore_command_register: bool,
33
- dividing_line: StaticDividingLine | DynamicDividingLine,
34
- repeat_command_groups: bool,
35
- override_system_messages: bool,
36
- autocompleter: AutoCompleter,
37
- print_func: Callable[[str], None],
38
- ) -> None:
25
+ def __init__(self,
26
+ prompt: str,
27
+ initial_message: str,
28
+ farewell_message: str,
29
+ exit_command: Command,
30
+ system_router_title: str | None,
31
+ ignore_command_register: bool,
32
+ dividing_line: StaticDividingLine | DynamicDividingLine,
33
+ repeat_command_groups: bool,
34
+ override_system_messages: bool,
35
+ autocompleter: AutoCompleter,
36
+ print_func: Callable[[str], None]) -> None:
39
37
  self._prompt = prompt
40
38
  self._print_func = print_func
41
39
  self._exit_command = exit_command
@@ -49,30 +47,18 @@ class BaseApp:
49
47
  self._farewell_message = farewell_message
50
48
  self._initial_message = initial_message
51
49
 
52
- self._description_message_gen: Callable[[str, str], str] = (
53
- lambda command, description: f"[{command}] *=*=* {description}"
54
- )
50
+ self._description_message_gen: Callable[[str, str], str] = (lambda command, description: f"[{command}] *=*=* {description}")
55
51
  self._registered_routers: RegisteredRouters = RegisteredRouters()
56
52
  self._messages_on_startup: list[str] = []
57
53
 
58
- self._all_registered_triggers_in_lower: list[str] = []
54
+ self._all_registered_triggers_in_lower_case: list[str] = []
59
55
  self._all_registered_triggers_in_default_case: list[str] = []
60
56
 
61
- self._incorrect_input_syntax_handler: Callable[[str], None] = (
62
- lambda raw_command: print_func(f"Incorrect flag syntax: {raw_command}")
63
- )
64
- self._repeated_input_flags_handler: Callable[[str], None] = (
65
- lambda raw_command: print_func(f"Repeated input flags: {raw_command}")
66
- )
67
- self._empty_input_command_handler: Callable[[], None] = lambda: print_func(
68
- "Empty input command"
69
- )
70
- self._unknown_command_handler: Callable[[InputCommand], None] = (
71
- lambda command: print_func(f"Unknown command: {command.get_trigger()}")
72
- )
73
- self._exit_command_handler: Callable[[Response], None] = (
74
- lambda response: print_func(self._farewell_message)
75
- )
57
+ self._incorrect_input_syntax_handler: Callable[[str], None] = (lambda raw_command: print_func(f"Incorrect flag syntax: {raw_command}"))
58
+ self._repeated_input_flags_handler: Callable[[str], None] = (lambda raw_command: print_func(f"Repeated input flags: {raw_command}"))
59
+ self._empty_input_command_handler: Callable[[], None] = lambda: print_func("Empty input command")
60
+ self._unknown_command_handler: Callable[[InputCommand], None] = (lambda command: print_func(f"Unknown command: {command.get_trigger()}"))
61
+ self._exit_command_handler: Callable[[Response], None] = (lambda response: print_func(self._farewell_message))
76
62
 
77
63
  def set_description_message_pattern(self, _: Callable[[str, str], str]) -> None:
78
64
  """
@@ -208,7 +194,7 @@ class BaseApp:
208
194
  """
209
195
  input_command_trigger = command.get_trigger()
210
196
  if self._ignore_command_register:
211
- if input_command_trigger.lower() in self._all_registered_triggers_in_lower:
197
+ if input_command_trigger.lower() in self._all_registered_triggers_in_lower_case:
212
198
  return False
213
199
  else:
214
200
  if input_command_trigger in self._all_registered_triggers_in_default_case:
@@ -249,7 +235,7 @@ class BaseApp:
249
235
 
250
236
  def _most_similar_command(self, unknown_command: str) -> str | None:
251
237
  all_commands = (
252
- self._all_registered_triggers_in_lower
238
+ self._all_registered_triggers_in_lower_case
253
239
  if self._ignore_command_register
254
240
  else self._all_registered_triggers_in_default_case
255
241
  )
@@ -318,21 +304,22 @@ class BaseApp:
318
304
  self._setup_system_router()
319
305
 
320
306
  for router_entity in self._registered_routers:
321
- self._all_registered_triggers_in_default_case.extend(
322
- router_entity.get_triggers()
323
- )
324
- self._all_registered_triggers_in_default_case.extend(
325
- router_entity.get_aliases()
326
- )
307
+ self._all_registered_triggers_in_default_case.extend(router_entity.get_triggers())
308
+ self._all_registered_triggers_in_default_case.extend(router_entity.get_aliases())
327
309
 
328
- self._all_registered_triggers_in_lower.extend(
329
- [x.lower() for x in router_entity.get_triggers()]
330
- )
331
- self._all_registered_triggers_in_lower.extend(
332
- [x.lower() for x in router_entity.get_aliases()]
333
- )
310
+ self._all_registered_triggers_in_lower_case.extend([x.lower() for x in router_entity.get_triggers()])
311
+ self._all_registered_triggers_in_lower_case.extend([x.lower() for x in router_entity.get_aliases()])
312
+
313
+ self._autocompleter.initial_setup(self._all_registered_triggers_in_lower_case)
334
314
 
335
- self._autocompleter.initial_setup(self._all_registered_triggers_in_lower)
315
+ if self._ignore_command_register:
316
+ for cmd in set(self._all_registered_triggers_in_lower_case):
317
+ if self._all_registered_triggers_in_lower_case.count(cmd) != 1:
318
+ Console().print(f"\n[b red]WARNING:[/b red] Overlapping trigger or alias: [b blue]{cmd}[/b blue]")
319
+ else:
320
+ for cmd in set(self._all_registered_triggers_in_default_case):
321
+ if self._all_registered_triggers_in_default_case.count(cmd) != 1:
322
+ Console().print(f"\n[b red]WARNING:[/b red] Overlapping trigger or alias: [b blue]{cmd}[/b blue]")
336
323
 
337
324
  if not self._override_system_messages:
338
325
  self._setup_default_view()
@@ -349,20 +336,18 @@ class BaseApp:
349
336
 
350
337
 
351
338
  class App(BaseApp):
352
- def __init__(
353
- self,
354
- prompt: str = "What do you want to do?\n",
355
- initial_message: str = "\nArgenta\n",
356
- farewell_message: str = "\nSee you\n",
357
- exit_command: Command = Command("Q", "Exit command"),
358
- system_router_title: str | None = "System points:",
359
- ignore_command_register: bool = True,
360
- dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
361
- repeat_command_groups: bool = True,
362
- override_system_messages: bool = False,
363
- autocompleter: AutoCompleter = AutoCompleter(),
364
- print_func: Callable[[str], None] = Console().print,
365
- ) -> None:
339
+ def __init__(self,
340
+ prompt: str = "What do you want to do?\n",
341
+ initial_message: str = "Argenta\n",
342
+ farewell_message: str = "\nSee you\n",
343
+ exit_command: Command = Command("Q", "Exit command"),
344
+ system_router_title: str | None = "System points:",
345
+ ignore_command_register: bool = True,
346
+ dividing_line: StaticDividingLine | DynamicDividingLine = StaticDividingLine(),
347
+ repeat_command_groups: bool = True,
348
+ override_system_messages: bool = False,
349
+ autocompleter: AutoCompleter = AutoCompleter(),
350
+ print_func: Callable[[str], None] = Console().print) -> None:
366
351
  """
367
352
  Public. The essence of the application itself.
368
353
  Configures and manages all aspects of the behavior and presentation of the user interacting with the user
@@ -379,19 +364,17 @@ class App(BaseApp):
379
364
  :param print_func: system messages text output function
380
365
  :return: None
381
366
  """
382
- super().__init__(
383
- prompt=prompt,
384
- initial_message=initial_message,
385
- farewell_message=farewell_message,
386
- exit_command=exit_command,
387
- system_router_title=system_router_title,
388
- ignore_command_register=ignore_command_register,
389
- dividing_line=dividing_line,
390
- repeat_command_groups=repeat_command_groups,
391
- override_system_messages=override_system_messages,
392
- autocompleter=autocompleter,
393
- print_func=print_func,
394
- )
367
+ super().__init__(prompt=prompt,
368
+ initial_message=initial_message,
369
+ farewell_message=farewell_message,
370
+ exit_command=exit_command,
371
+ system_router_title=system_router_title,
372
+ ignore_command_register=ignore_command_register,
373
+ dividing_line=dividing_line,
374
+ repeat_command_groups=repeat_command_groups,
375
+ override_system_messages=override_system_messages,
376
+ autocompleter=autocompleter,
377
+ print_func=print_func)
395
378
 
396
379
  def run_polling(self) -> None:
397
380
  """
@@ -420,7 +403,7 @@ class App(BaseApp):
420
403
  system_router.finds_appropriate_handler(input_command)
421
404
  if self._ignore_command_register:
422
405
  self._autocompleter.exit_setup(
423
- self._all_registered_triggers_in_lower
406
+ self._all_registered_triggers_in_lower_case
424
407
  )
425
408
  else:
426
409
  self._autocompleter.exit_setup(
@@ -192,14 +192,12 @@ class Router:
192
192
  pass
193
193
  else:
194
194
  file_path: str = getsourcefile(func)
195
- source_line: int = getsourcelines(func)[1] + 1
195
+ source_line: int = getsourcelines(func)[1]
196
196
  fprint = Console().print
197
- fprint(
198
- f'\nFile "{file_path}", line {source_line}\n[b red]WARNING:[/b red] [i]The typehint '
197
+ fprint(f'\nFile "{file_path}", line {source_line}\n[b red]WARNING:[/b red] [i]The typehint '
199
198
  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
- )
199
+ f" [i]but[/i] [bold blue]{arg_annotation}[/bold blue] [i]is specified[/i]",
200
+ highlight=False)
203
201
 
204
202
  def set_command_register_ignore(self, _: bool) -> None:
205
203
  """
@@ -33,13 +33,13 @@ class MyTestCase(unittest.TestCase):
33
33
  def test_is_unknown_command1(self):
34
34
  app = App()
35
35
  app.set_unknown_command_handler(lambda command: None)
36
- app._all_registered_triggers_in_lower = ['fr', 'tr', 'de']
36
+ app._all_registered_triggers_in_lower_case = ['fr', 'tr', 'de']
37
37
  self.assertEqual(app._is_unknown_command(InputCommand('fr')), False)
38
38
 
39
39
  def test_is_unknown_command2(self):
40
40
  app = App()
41
41
  app.set_unknown_command_handler(lambda command: None)
42
- app._all_registered_triggers_in_lower = ['fr', 'tr', 'de']
42
+ app._all_registered_triggers_in_lower_case = ['fr', 'tr', 'de']
43
43
  self.assertEqual(app._is_unknown_command(InputCommand('cr')), True)
44
44
 
45
45
  def test_is_unknown_command3(self):
@@ -1,89 +0,0 @@
1
- from argenta.app import App
2
- from argenta.app.autocompleter import AutoCompleter
3
- from argenta.router import Router
4
- from argenta.command import Command
5
- from argenta.orchestrator import Orchestrator
6
- from argenta.app.dividing_line import DynamicDividingLine
7
- from argenta.response import Response
8
- import platform
9
- import psutil
10
- import os
11
- import subprocess
12
- import socket
13
-
14
- # Маршрутизатор для работы с файлами
15
- file_router = Router("Файловые операции")
16
-
17
-
18
- @file_router.command(Command("list", "Список файлов"))
19
- def list_files(response: Response):
20
- files = os.listdir()
21
- for file in files:
22
- print(file)
23
-
24
-
25
- @file_router.command(Command("size", "Размер файла"))
26
- def file_size(response: Response):
27
- file_name = input("Введите имя файла: ")
28
- if os.path.exists(file_name):
29
- size = os.path.getsize(file_name)
30
- print(f"Размер файла {file_name}: {size} байт")
31
- else:
32
- print(f"Файл {file_name} не найден")
33
-
34
-
35
- # Маршрутизатор для системных операций
36
- system_router = Router("Системные операции")
37
-
38
-
39
- @system_router.command(Command("info", "Информация о системе"))
40
- def system_info(response: Response):
41
- print(f"Система: {platform.system()}")
42
- print(f"Версия: {platform.version()}")
43
- print(f"Архитектура: {platform.architecture()}")
44
- print(f"Процессор: {platform.processor()}")
45
-
46
-
47
- @system_router.command(Command("memory", "Информация о памяти"))
48
- def memory_info(response: Response):
49
- memory = psutil.virtual_memory()
50
- print(f"Всего памяти: {memory.total / (1024**3):.2f} ГБ")
51
- print(f"Доступно: {memory.available / (1024**3):.2f} ГБ")
52
- print(f"Использовано: {memory.used / (1024**3):.2f} ГБ ({memory.percent}%)")
53
-
54
-
55
- # Маршрутизатор для сетевых операций
56
- network_router = Router("Сетевые операции")
57
-
58
-
59
- @network_router.command(Command("ping", "Проверка доступности хоста"))
60
- def ping_host(response: Response):
61
- host = input("Введите имя хоста: ")
62
- print(f"Пингую {host}...")
63
- subprocess.run(["ping", "-c", "4", host])
64
-
65
-
66
- @network_router.command(Command("ip", "Показать IP-адреса"))
67
- def show_ip(response: Response):
68
- hostname = socket.gethostname()
69
- print(f"Имя хоста: {hostname}")
70
- print(f"IP-адрес: {socket.gethostbyname(hostname)}")
71
-
72
-
73
- # Создание приложения и регистрация маршрутизаторов
74
- app = App(
75
- prompt="System> ",
76
- initial_message="Pingator",
77
- dividing_line=DynamicDividingLine("*"),
78
- autocompleter=AutoCompleter(".hist", "e"),
79
- )
80
-
81
- # Добавляем все маршрутизаторы
82
- app.include_routers(file_router, system_router, network_router)
83
-
84
- # Добавляем сообщение при запуске
85
- app.add_message_on_startup("Для просмотра доступных команд нажмите Enter")
86
-
87
- # Запускаем приложение
88
- orchestrator = Orchestrator()
89
- orchestrator.start_polling(app)
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