argenta 1.0.0a5__tar.gz → 1.0.0b2__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 (68) hide show
  1. {argenta-1.0.0a5 → argenta-1.0.0b2}/PKG-INFO +4 -4
  2. {argenta-1.0.0a5 → argenta-1.0.0b2}/README.md +1 -1
  3. argenta-1.0.0b2/imgs/mock_app_preview4.png +0 -0
  4. {argenta-1.0.0a5 → argenta-1.0.0b2}/mock/default_mock_app/main.py +5 -6
  5. argenta-1.0.0b2/mock/local_test.py +23 -0
  6. argenta-1.0.0b2/mock/mock_app/handlers/routers.py +31 -0
  7. {argenta-1.0.0a5 → argenta-1.0.0b2}/mock/mock_app/main.py +2 -1
  8. {argenta-1.0.0a5 → argenta-1.0.0b2}/pyproject.toml +3 -3
  9. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/app/models.py +41 -20
  10. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/command/exceptions.py +1 -1
  11. argenta-1.0.0b2/src/argenta/command/flag/__init__.py +4 -0
  12. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/command/flag/models.py +24 -124
  13. argenta-1.0.0b2/src/argenta/command/flags/__init__.py +10 -0
  14. argenta-1.0.0b2/src/argenta/command/flags/models.py +87 -0
  15. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/command/models.py +18 -10
  16. argenta-1.0.0b2/src/argenta/response/__init__.py +5 -0
  17. argenta-1.0.0b2/src/argenta/response/entity.py +27 -0
  18. argenta-1.0.0b2/src/argenta/response/status.py +9 -0
  19. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/router/command_handler/entity.py +7 -11
  20. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/router/entity.py +87 -53
  21. {argenta-1.0.0a5 → argenta-1.0.0b2}/tests/system_tests/test_system_handling_non_standard_behavior.py +44 -30
  22. {argenta-1.0.0a5 → argenta-1.0.0b2}/tests/system_tests/test_system_handling_normal_behavior.py +48 -33
  23. {argenta-1.0.0a5 → argenta-1.0.0b2}/tests/unit_tests/test_command.py +26 -12
  24. {argenta-1.0.0a5 → argenta-1.0.0b2}/tests/unit_tests/test_flag.py +2 -1
  25. {argenta-1.0.0a5 → argenta-1.0.0b2}/tests/unit_tests/test_router.py +34 -50
  26. argenta-1.0.0a5/mock/local_test.py +0 -6
  27. argenta-1.0.0a5/mock/mock_app/handlers/routers.py +0 -22
  28. argenta-1.0.0a5/src/argenta/command/flag/__init__.py +0 -4
  29. {argenta-1.0.0a5 → argenta-1.0.0b2}/.github/workflows/ruff.yml +0 -0
  30. {argenta-1.0.0a5 → argenta-1.0.0b2}/.github/workflows/tests.yml +0 -0
  31. {argenta-1.0.0a5 → argenta-1.0.0b2}/.gitignore +0 -0
  32. {argenta-1.0.0a5 → argenta-1.0.0b2}/LICENSE +0 -0
  33. {argenta-1.0.0a5 → argenta-1.0.0b2}/imgs/mock_app_preview1.png +0 -0
  34. {argenta-1.0.0a5 → argenta-1.0.0b2}/imgs/mock_app_preview2.png +0 -0
  35. {argenta-1.0.0a5 → argenta-1.0.0b2}/imgs/mock_app_preview3.png +0 -0
  36. {argenta-1.0.0a5 → argenta-1.0.0b2}/mock/__init__.py +0 -0
  37. {argenta-1.0.0a5 → argenta-1.0.0b2}/mock/default_mock_app/__init__.py +0 -0
  38. {argenta-1.0.0a5 → argenta-1.0.0b2}/mock/mock_app/__init__.py +0 -0
  39. {argenta-1.0.0a5 → argenta-1.0.0b2}/mock/mock_app/handlers/__init__.py +0 -0
  40. {argenta-1.0.0a5 → argenta-1.0.0b2}/mock/mock_app/handlers/handlers_implementation/__init__.py +0 -0
  41. {argenta-1.0.0a5 → argenta-1.0.0b2}/mock/mock_app/handlers/handlers_implementation/help_command.py +0 -0
  42. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/__init__.py +0 -0
  43. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/__init__.py +0 -0
  44. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/app/__init__.py +0 -0
  45. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/app/autocompleter/__init__.py +0 -0
  46. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/app/autocompleter/entity.py +0 -0
  47. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/app/defaults.py +0 -0
  48. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/app/dividing_line/__init__.py +0 -0
  49. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/app/dividing_line/models.py +0 -0
  50. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/app/registered_routers/__init__.py +0 -0
  51. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/app/registered_routers/entity.py +0 -0
  52. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/command/__init__.py +0 -0
  53. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/command/flag/defaults.py +0 -0
  54. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/orchestrator/__init__.py +0 -0
  55. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/orchestrator/argparser/__init__.py +0 -0
  56. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/orchestrator/argparser/arguments/__init__.py +0 -0
  57. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/orchestrator/argparser/arguments/models.py +0 -0
  58. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/orchestrator/argparser/entity.py +0 -0
  59. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/orchestrator/entity.py +0 -0
  60. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/router/__init__.py +0 -0
  61. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/router/command_handler/__init__.py +0 -0
  62. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/router/defaults.py +0 -0
  63. {argenta-1.0.0a5 → argenta-1.0.0b2}/src/argenta/router/exceptions.py +0 -0
  64. {argenta-1.0.0a5 → argenta-1.0.0b2}/tests/__init__.py +0 -0
  65. {argenta-1.0.0a5 → argenta-1.0.0b2}/tests/system_tests/__init__.py +0 -0
  66. {argenta-1.0.0a5 → argenta-1.0.0b2}/tests/unit_tests/__init__.py +0 -0
  67. {argenta-1.0.0a5 → argenta-1.0.0b2}/tests/unit_tests/test_app.py +0 -0
  68. {argenta-1.0.0a5 → argenta-1.0.0b2}/tests/unit_tests/test_dividing_line.py +0 -0
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: argenta
3
- Version: 1.0.0a5
4
- Summary: Python library for creating TUI
3
+ Version: 1.0.0b2
4
+ Summary: Python library for building modular CLI applications
5
5
  Author-email: kolo <kolo.is.main@gmail.com>
6
6
  License: MIT
7
7
  License-File: LICENSE
8
8
  Requires-Python: <4.0,>=3.11
9
9
  Requires-Dist: art<7.0,>=6.4
10
- Requires-Dist: pyreadline3<4.0.0,>=3.5.4
10
+ Requires-Dist: pyreadline3>=3.5.4
11
11
  Requires-Dist: rich<15.0.0,>=14.0.0
12
12
  Description-Content-Type: text/markdown
13
13
 
@@ -87,7 +87,7 @@ Description-Content-Type: text/markdown
87
87
 
88
88
  ---
89
89
 
90
- ![preview](https://github.com/koloideal/Argenta/blob/kolo/imgs/mock_app_preview3.png?raw=True)
90
+ ![preview](https://github.com/koloideal/Argenta/blob/kolo/imgs/mock_app_preview4.png?raw=True)
91
91
  An example of the TUI appearance
92
92
 
93
93
  ---
@@ -74,7 +74,7 @@
74
74
 
75
75
  ---
76
76
 
77
- ![preview](https://github.com/koloideal/Argenta/blob/kolo/imgs/mock_app_preview3.png?raw=True)
77
+ ![preview](https://github.com/koloideal/Argenta/blob/kolo/imgs/mock_app_preview4.png?raw=True)
78
78
  An example of the TUI appearance
79
79
 
80
80
  ---
@@ -1,8 +1,7 @@
1
- #from mock.mock_app.handlers.routers import work_router
1
+ from mock.mock_app.handlers.routers import work_router
2
2
 
3
3
  from argenta.app import App
4
4
  from argenta.app.defaults import PredefinedMessages
5
- from argenta.app.dividing_line import DynamicDividingLine
6
5
  from argenta.app.autocompleter import AutoCompleter
7
6
  from argenta.orchestrator import Orchestrator
8
7
  from argenta.orchestrator.argparser import ArgParser
@@ -10,16 +9,16 @@ from argenta.orchestrator.argparser.arguments import BooleanArgument
10
9
 
11
10
 
12
11
  arg_parser = ArgParser(processed_args=[BooleanArgument('repeat')])
13
- app: App = App()
12
+ app: App = App(autocompleter=AutoCompleter('.hist'))
14
13
  orchestrator: Orchestrator = Orchestrator()
15
14
 
16
15
 
17
16
  def main():
18
- #app.include_router(work_router)
17
+ app.include_router(work_router)
19
18
 
20
- '''app.add_message_on_startup(PredefinedMessages.USAGE)
19
+ app.add_message_on_startup(PredefinedMessages.USAGE)
21
20
  app.add_message_on_startup(PredefinedMessages.AUTOCOMPLETE)
22
- app.add_message_on_startup(PredefinedMessages.HELP)'''
21
+ app.add_message_on_startup(PredefinedMessages.HELP)
23
22
 
24
23
  orchestrator.start_polling(app)
25
24
 
@@ -0,0 +1,23 @@
1
+ from argenta.response import Response, Status
2
+ from argenta.app import App
3
+ from argenta.app.dividing_line import StaticDividingLine, DynamicDividingLine
4
+ from argenta.app.autocompleter import AutoCompleter
5
+ from argenta.app.defaults import PredefinedMessages
6
+ from argenta.command import Command
7
+ from argenta.command.flags import Flags, InputFlags, InvalidValueInputFlags, UndefinedInputFlags, ValidInputFlags
8
+ from argenta.command.flag import Flag, InputFlag
9
+ from argenta.command.flag.defaults import PredefinedFlags
10
+ from argenta.router import Router
11
+ from argenta.orchestrator import Orchestrator
12
+
13
+ from argenta.command.models import InputCommand
14
+ import inspect
15
+
16
+
17
+ router = Router()
18
+
19
+
20
+ @router.command(Command('some'))
21
+ def handler(res: Response) -> Response:
22
+ pass
23
+
@@ -0,0 +1,31 @@
1
+ from rich.console import Console
2
+
3
+ from argenta.command import Command
4
+ from argenta.command.flag.defaults import PredefinedFlags
5
+ from argenta.command.flags import Flags
6
+ from argenta.response import Response
7
+ from argenta.router import Router
8
+
9
+
10
+ work_router: Router = Router(title='Work points:')
11
+
12
+ console = Console()
13
+
14
+
15
+ @work_router.command(Command('get', 'Get Help', aliases=['help', 'Get_help'], flags=Flags(PredefinedFlags.PORT, PredefinedFlags.HOST)))
16
+ def command_help(response: Response):
17
+ print(response.status)
18
+ print(response.undefined_flags.get_flags())
19
+ print(response.valid_flags.get_flags())
20
+ print(response.invalid_value_flags.get_flags())
21
+
22
+
23
+ @work_router.command('run')
24
+ def command_start_solving(response: Response):
25
+ print(response.status)
26
+ print(response.undefined_flags.get_flags())
27
+ print(response.valid_flags.get_flags())
28
+ print(response.invalid_value_flags.get_flags())
29
+
30
+
31
+
@@ -11,7 +11,8 @@ from argenta.orchestrator.argparser.arguments import BooleanArgument
11
11
 
12
12
  arg_parser = ArgParser(processed_args=[BooleanArgument('repeat')])
13
13
  app: App = App(dividing_line=DynamicDividingLine(),
14
- autocompleter=AutoCompleter('./mock/.hist'))
14
+ autocompleter=AutoCompleter('./mock/.hist'),
15
+ repeat_command_groups=False,)
15
16
  orchestrator: Orchestrator = Orchestrator(arg_parser)
16
17
 
17
18
 
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "argenta"
3
- version = "1.0.0-alpha5"
4
- description = "Python library for creating TUI"
3
+ version = "1.0.0-beta2"
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.11, <4.0"
7
7
  readme = "README.md"
@@ -9,7 +9,7 @@ license = { text = "MIT" }
9
9
  dependencies = [
10
10
  "rich (>=14.0.0,<15.0.0)",
11
11
  "art (>=6.4,<7.0)",
12
- "pyreadline3 (>=3.5.4,<4.0.0)",
12
+ "pyreadline3>=3.5.4",
13
13
  ]
14
14
 
15
15
  [dependency-groups]
@@ -16,6 +16,7 @@ from argenta.command.exceptions import (UnprocessedInputFlagException,
16
16
  EmptyInputCommandException,
17
17
  BaseInputCommandException)
18
18
  from argenta.app.registered_routers.entity import RegisteredRouters
19
+ from argenta.response import Response
19
20
 
20
21
 
21
22
 
@@ -58,7 +59,7 @@ class BaseApp:
58
59
  self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: {raw_command}')
59
60
  self._empty_input_command_handler: Callable[[], None] = lambda: print_func('Empty input command')
60
61
  self._unknown_command_handler: Callable[[InputCommand], None] = lambda command: print_func(f"Unknown command: {command.get_trigger()}")
61
- self._exit_command_handler: Callable[[], None] = lambda: print_func(self._farewell_message)
62
+ self._exit_command_handler: Callable[[Response], None] = lambda response: print_func(self._farewell_message)
62
63
 
63
64
 
64
65
  def set_description_message_pattern(self, _: Callable[[str, str], str]) -> None:
@@ -210,30 +211,51 @@ class BaseApp:
210
211
  system_router.set_title(self._system_router_title)
211
212
 
212
213
  @system_router.command(self._exit_command)
213
- def exit_command():
214
- self._exit_command_handler()
214
+ def exit_command(response: Response) -> None:
215
+ self._exit_command_handler(response)
215
216
 
216
217
  if system_router not in self._registered_routers.get_registered_routers():
217
218
  system_router.set_command_register_ignore(self._ignore_command_register)
218
219
  self._registered_routers.add_registered_router(system_router)
219
220
 
220
221
 
222
+ def _most_similar_command(self, unknown_command: str) -> str | None:
223
+ all_commands = self._all_registered_triggers_in_lower if self._ignore_command_register else self._all_registered_triggers_in_default_case
224
+ matches: list[str] | list = sorted(cmd for cmd in all_commands if cmd.startswith(unknown_command))
225
+ if not matches:
226
+ matches: list[str] | list = sorted(cmd for cmd in all_commands if unknown_command.startswith(cmd))
227
+ if len(matches) == 1:
228
+ return matches[0]
229
+ elif len(matches) > 1:
230
+ return sorted(matches, key=lambda cmd: len(cmd))[0]
231
+ else:
232
+ return None
233
+
234
+
221
235
  def _setup_default_view(self) -> None:
222
236
  """
223
237
  Private. Sets up default app view
224
238
  :return: None
225
239
  """
226
- if not self._override_system_messages:
227
- self._initial_message = f'\n[bold red]{text2art(self._initial_message, font="tarty1")}\n\n'
228
- self._farewell_message = (f'[bold red]\n{text2art(f"\n{self._farewell_message}\n", font="chanky")}[/bold red]\n'
229
- f'[red i]github.com/koloideal/Argenta[/red i] | [red bold i]made by kolo[/red bold i]\n')
230
- self._description_message_gen = lambda command, description: (f'[bold red]{escape("[" + command + "]")}[/bold red] '
231
- f'[blue dim]*=*=*[/blue dim] '
232
- f'[bold yellow italic]{escape(description)}')
233
- self._invalid_input_flags_handler = lambda raw_command: self._print_func(f'[red bold]Incorrect flag syntax: {escape(raw_command)}')
234
- self._repeated_input_flags_handler = lambda raw_command: self._print_func(f'[red bold]Repeated input flags: {escape(raw_command)}')
235
- self._empty_input_command_handler = lambda: self._print_func('[red bold]Empty input command')
236
- self._unknown_command_handler = lambda command: self._print_func(f"[red bold]Unknown command: {escape(command.get_trigger())}")
240
+ self._prompt = '[italic dim bold]What do you want to do?\n'
241
+ self._initial_message = f'\n[bold red]{text2art(self._initial_message, font="tarty1")}\n'
242
+ self._farewell_message = (f'[bold red]\n{text2art(f"\n{self._farewell_message}\n", font="chanky")}[/bold red]\n'
243
+ f'[red i]github.com/koloideal/Argenta[/red i] | [red bold i]made by kolo[/red bold i]\n')
244
+ self._description_message_gen = lambda command, description: (f'[bold red]{escape("[" + command + "]")}[/bold red] '
245
+ f'[blue dim]*=*=*[/blue dim] '
246
+ f'[bold yellow italic]{escape(description)}')
247
+ self._invalid_input_flags_handler = lambda raw_command: self._print_func(f'[red bold]Incorrect flag syntax: {escape(raw_command)}')
248
+ self._repeated_input_flags_handler = lambda raw_command: self._print_func(f'[red bold]Repeated input flags: {escape(raw_command)}')
249
+ self._empty_input_command_handler = lambda: self._print_func('[red bold]Empty input command')
250
+
251
+ def unknown_command_handler(command: InputCommand) -> None:
252
+ cmd_trg: str = command.get_trigger()
253
+ mst_sim_cmd: str | None = self._most_similar_command(cmd_trg)
254
+ first_part_of_text = f"[red]Unknown command:[/red] [blue]{escape(cmd_trg)}[/blue]"
255
+ second_part_of_text = ('[red], most similar:[/red] ' + ('[blue]' + mst_sim_cmd + '[/blue]')) if mst_sim_cmd else ''
256
+ self._print_func(first_part_of_text + second_part_of_text)
257
+
258
+ self._unknown_command_handler = unknown_command_handler
237
259
 
238
260
 
239
261
  def _pre_cycle_setup(self) -> None:
@@ -241,7 +263,6 @@ class BaseApp:
241
263
  Private. Configures various aspects of the application before the start of the cycle
242
264
  :return: None
243
265
  """
244
- self._setup_default_view()
245
266
  self._setup_system_router()
246
267
 
247
268
  for router_entity in self._registered_routers:
@@ -253,12 +274,15 @@ class BaseApp:
253
274
 
254
275
  self._autocompleter.initial_setup(self._all_registered_triggers_in_lower)
255
276
 
277
+ if not self._override_system_messages:
278
+ self._setup_default_view()
279
+
256
280
  self._print_func(self._initial_message)
257
281
 
258
282
  for message in self._messages_on_startup:
259
283
  self._print_func(message)
260
284
  if self._messages_on_startup:
261
- print('\n\n')
285
+ print('\n')
262
286
 
263
287
  if not self._repeat_command_groups_description:
264
288
  self._print_command_group_description()
@@ -267,7 +291,7 @@ class BaseApp:
267
291
 
268
292
  class App(BaseApp):
269
293
  def __init__(self,
270
- prompt: str = '[italic dim bold]What do you want to do?\n',
294
+ prompt: str = 'What do you want to do?\n',
271
295
  initial_message: str = '\nArgenta\n',
272
296
  farewell_message: str = '\nSee you\n',
273
297
  exit_command: Command = Command('Q', 'Exit command'),
@@ -346,9 +370,6 @@ class App(BaseApp):
346
370
  res: str = f.getvalue()
347
371
  self._print_framed_text(res)
348
372
 
349
- if not self._repeat_command_groups_description:
350
- self._print_func(self._prompt)
351
-
352
373
 
353
374
  def include_router(self, router: Router) -> None:
354
375
  """
@@ -1,4 +1,4 @@
1
- from argenta.command.flag.models import InputFlag, Flag
1
+ from argenta.command.flag.models import Flag, InputFlag
2
2
 
3
3
 
4
4
  class BaseInputCommandException(Exception):
@@ -0,0 +1,4 @@
1
+ __all__ = ["Flag", "InputFlag"]
2
+
3
+
4
+ from argenta.command.flag.models import Flag, InputFlag
@@ -1,8 +1,8 @@
1
1
  from typing import Literal, Pattern
2
- from abc import ABC, abstractmethod
3
2
 
4
3
 
5
- class BaseFlag(ABC):
4
+
5
+ class BaseFlag:
6
6
  def __init__(self, name: str,
7
7
  prefix: Literal['-', '--', '---'] = '--') -> None:
8
8
  """
@@ -36,37 +36,8 @@ class BaseFlag(ABC):
36
36
  """
37
37
  return self._prefix
38
38
 
39
-
40
-
41
- class InputFlag(BaseFlag):
42
- def __init__(self, name: str,
43
- prefix: Literal['-', '--', '---'] = '--',
44
- value: str = None):
45
- """
46
- Public. The entity of the flag of the entered command
47
- :param name: the name of the input flag
48
- :param prefix: the prefix of the input flag
49
- :param value: the value of the input flag
50
- :return: None
51
- """
52
- super().__init__(name, prefix)
53
- self._flag_value = value
54
-
55
- def get_value(self) -> str | None:
56
- """
57
- Public. Returns the value of the flag
58
- :return: the value of the flag as str
59
- """
60
- return self._flag_value
61
-
62
- def set_value(self, value):
63
- """
64
- Private. Sets the value of the flag
65
- :param value: the fag value to set
66
- :return: None
67
- """
68
- self._flag_value = value
69
-
39
+ def __eq__(self, other) -> bool:
40
+ return self.get_string_entity() == other.get_string_entity()
70
41
 
71
42
 
72
43
  class Flag(BaseFlag):
@@ -113,106 +84,35 @@ class Flag(BaseFlag):
113
84
  return True
114
85
 
115
86
 
116
-
117
- class BaseFlags(ABC):
118
- """
119
- Private. Base class for groups of flags
120
- """
121
- __slots__ = ('_flags',)
122
-
123
- @abstractmethod
124
- def get_flags(self):
125
- """
126
- Public. Returns a list of flags
127
- :return: list of flags
128
- """
129
- pass
130
-
131
- @abstractmethod
132
- def add_flag(self, flag: Flag | InputFlag):
133
- """
134
- Public. Adds a flag to the list of flags
135
- :param flag: flag to add
136
- :return: None
137
- """
138
- pass
139
-
140
- @abstractmethod
141
- def add_flags(self, flags: list[Flag] | list[InputFlag]):
87
+ class InputFlag(BaseFlag):
88
+ def __init__(self, name: str,
89
+ prefix: Literal['-', '--', '---'] = '--',
90
+ value: str = None):
142
91
  """
143
- Public. Adds a list of flags to the list of flags
144
- :param flags: list of flags to add
92
+ Public. The entity of the flag of the entered command
93
+ :param name: the name of the input flag
94
+ :param prefix: the prefix of the input flag
95
+ :param value: the value of the input flag
145
96
  :return: None
146
97
  """
147
- pass
148
-
149
- @abstractmethod
150
- def get_flag(self, name: str):
151
- """
152
- Public. Returns the flag entity by its name or None if not found
153
- :param name: the name of the flag to get
154
- :return: entity of the flag or None
155
- """
156
- pass
157
-
158
- def __iter__(self):
159
- return iter(self._flags)
160
-
161
- def __next__(self):
162
- return next(iter(self))
163
-
164
- def __getitem__(self, item):
165
- return self._flags[item]
166
-
167
-
98
+ super().__init__(name, prefix)
99
+ self._flag_value = value
168
100
 
169
- class Flags(BaseFlags, ABC):
170
- def __init__(self, *flags: Flag):
101
+ def get_value(self) -> str | None:
171
102
  """
172
- Public. A model that combines the registered flags
173
- :param flags: the flags that will be registered
174
- :return: None
103
+ Public. Returns the value of the flag
104
+ :return: the value of the flag as str
175
105
  """
176
- self._flags = flags if flags else []
177
-
178
- def get_flags(self) -> list[Flag]:
179
- return self._flags
180
-
181
- def add_flag(self, flag: Flag):
182
- self._flags.append(flag)
183
-
184
- def add_flags(self, flags: list[Flag]):
185
- self._flags.extend(flags)
186
-
187
- def get_flag(self, name: str) -> Flag | None:
188
- if name in [flag.get_name() for flag in self._flags]:
189
- return list(filter(lambda flag: flag.get_name() == name, self._flags))[0]
190
- else:
191
- return None
192
-
193
-
106
+ return self._flag_value
194
107
 
195
- class InputFlags(BaseFlags, ABC):
196
- def __init__(self, *flags: InputFlag):
108
+ def set_value(self, value):
197
109
  """
198
- Public. A model that combines the input flags of the input command
199
- :param flags: all input flags
110
+ Private. Sets the value of the flag
111
+ :param value: the fag value to set
200
112
  :return: None
201
113
  """
202
- self._flags = flags if flags else []
203
-
204
- def get_flags(self) -> list[InputFlag]:
205
- return self._flags
206
-
207
- def add_flag(self, flag: InputFlag):
208
- self._flags.append(flag)
209
-
210
- def add_flags(self, flags: list[InputFlag]):
211
- self._flags.extend(flags)
114
+ self._flag_value = value
212
115
 
213
- def get_flag(self, name: str) -> InputFlag | None:
214
- if name in [flag.get_name() for flag in self._flags]:
215
- return list(filter(lambda flag: flag.get_name() == name, self._flags))[0]
216
- else:
217
- return None
116
+ def __eq__(self, other) -> bool:
117
+ return self.get_string_entity() == other.get_string_entity() and self.get_value() == other.get_value()
218
118
 
@@ -0,0 +1,10 @@
1
+ __all__ = ["Flags", "InputFlags",
2
+ "UndefinedInputFlags",
3
+ "InvalidValueInputFlags",
4
+ "ValidInputFlags"]
5
+
6
+
7
+ from argenta.command.flags.models import (Flags, InputFlags,
8
+ UndefinedInputFlags,
9
+ InvalidValueInputFlags,
10
+ ValidInputFlags)
@@ -0,0 +1,87 @@
1
+ from argenta.command.flag.models import InputFlag, Flag
2
+ from typing import Generic, TypeVar
3
+
4
+
5
+
6
+ FlagType = TypeVar('FlagType')
7
+
8
+
9
+ class BaseFlags(Generic[FlagType]):
10
+ def __init__(self, *flags: FlagType):
11
+ """
12
+ Public. A model that combines the registered flags
13
+ :param flags: the flags that will be registered
14
+ :return: None
15
+ """
16
+ self._flags = flags if flags else []
17
+
18
+ def get_flags(self) -> list[FlagType]:
19
+ """
20
+ Public. Returns a list of flags
21
+ :return: list of flags as list[FlagType]
22
+ """
23
+ return self._flags
24
+
25
+ def add_flag(self, flag: FlagType):
26
+ """
27
+ Public. Adds a flag to the list of flags
28
+ :param flag: flag to add
29
+ :return: None
30
+ """
31
+ self._flags.append(flag)
32
+
33
+ def add_flags(self, flags: list[FlagType]):
34
+ """
35
+ Public. Adds a list of flags to the list of flags
36
+ :param flags: list of flags to add
37
+ :return: None
38
+ """
39
+ self._flags.extend(flags)
40
+
41
+ def get_flag(self, name: str) -> FlagType | None:
42
+ """
43
+ Public. Returns the flag entity by its name or None if not found
44
+ :param name: the name of the flag to get
45
+ :return: entity of the flag or None
46
+ """
47
+ if name in [flag.get_name() for flag in self._flags]:
48
+ return list(filter(lambda flag: flag.get_name() == name, self._flags))[0]
49
+ else:
50
+ return None
51
+
52
+ def __iter__(self):
53
+ return iter(self._flags)
54
+
55
+ def __next__(self):
56
+ return next(iter(self))
57
+
58
+ def __getitem__(self, item):
59
+ return self._flags[item]
60
+
61
+ def __bool__(self):
62
+ return bool(self._flags)
63
+
64
+ def __eq__(self, other):
65
+ if len(self.get_flags()) != len(other.get_flags()):
66
+ return False
67
+ else:
68
+ for flag, other_flag in zip(self.get_flags(), other.get_flags()):
69
+ if not flag == other_flag:
70
+ return False
71
+ return True
72
+
73
+
74
+ class Flags(BaseFlags[Flag]): pass
75
+
76
+
77
+ class InputFlags(BaseFlags[InputFlag]): pass
78
+
79
+
80
+ class ValidInputFlags(InputFlags): pass
81
+
82
+
83
+ class UndefinedInputFlags(InputFlags): pass
84
+
85
+
86
+ class InvalidValueInputFlags(InputFlags): pass
87
+
@@ -1,4 +1,5 @@
1
- from argenta.command.flag.models import Flag, InputFlag, Flags, InputFlags
1
+ from argenta.command.flag.models import Flag, InputFlag
2
+ from argenta.command.flags.models import InputFlags, Flags
2
3
  from argenta.command.exceptions import (UnprocessedInputFlagException,
3
4
  RepeatedInputFlagsException,
4
5
  EmptyInputCommandException)
@@ -38,7 +39,7 @@ class Command(BaseCommand):
38
39
  """
39
40
  super().__init__(trigger)
40
41
  self._registered_flags: Flags = flags if isinstance(flags, Flags) else Flags(flags) if isinstance(flags, Flag) else Flags()
41
- self._description = f'Description for "{self._trigger}" command' if not description else description
42
+ self._description = f'Very useful command' if not description else description
42
43
  self._aliases = aliases if isinstance(aliases, list) else []
43
44
 
44
45
  def get_registered_flags(self) -> Flags:
@@ -55,7 +56,7 @@ class Command(BaseCommand):
55
56
  """
56
57
  return self._aliases
57
58
 
58
- def validate_input_flag(self, flag: InputFlag) -> bool:
59
+ def validate_input_flag(self, flag: InputFlag) -> Literal['Undefined', 'Valid', 'Invalid']:
59
60
  """
60
61
  Private. Validates the input flag
61
62
  :param flag: input flag for validation
@@ -67,14 +68,21 @@ class Command(BaseCommand):
67
68
  if registered_flags.get_string_entity() == flag.get_string_entity():
68
69
  is_valid = registered_flags.validate_input_flag_value(flag.get_value())
69
70
  if is_valid:
70
- return True
71
+ return 'Valid'
72
+ else:
73
+ return 'Invalid'
74
+ else:
75
+ return 'Undefined'
71
76
  else:
72
77
  for registered_flag in registered_flags:
73
78
  if registered_flag.get_string_entity() == flag.get_string_entity():
74
79
  is_valid = registered_flag.validate_input_flag_value(flag.get_value())
75
80
  if is_valid:
76
- return True
77
- return False
81
+ return 'Valid'
82
+ else:
83
+ return 'Invalid'
84
+ return 'Undefined'
85
+ return 'Undefined'
78
86
 
79
87
  def get_description(self) -> str:
80
88
  """
@@ -131,11 +139,11 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
131
139
 
132
140
  for k, _ in enumerate(list_of_tokens):
133
141
  if _.startswith('-'):
134
- if current_flag_name or len(_) < 2 or len(_[:_.rfind('-')]) > 3:
142
+ if len(_) < 2 or len(_[:_.rfind('-')]) > 3:
135
143
  raise UnprocessedInputFlagException()
136
144
  current_flag_name = _
137
145
  else:
138
- if not current_flag_name:
146
+ if not current_flag_name or current_flag_value:
139
147
  raise UnprocessedInputFlagException()
140
148
  current_flag_value = _
141
149
 
@@ -144,9 +152,9 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
144
152
  if not list_of_tokens[k+1].startswith('-'):
145
153
  continue
146
154
 
147
- input_flag = InputFlag(name=current_flag_name[current_flag_name.rfind('-')+1:],
155
+ input_flag = InputFlag(name=current_flag_name[current_flag_name.rfind('-') + 1:],
148
156
  prefix=cast(Literal['-', '--', '---'],
149
- current_flag_name[:current_flag_name.rfind('-')+1]),
157
+ current_flag_name[:current_flag_name.rfind('-')+1]),
150
158
  value=current_flag_value)
151
159
 
152
160
  all_flags = [flag.get_string_entity() for flag in input_flags.get_flags()]
@@ -0,0 +1,5 @@
1
+ __all__ = ["Response", "Status"]
2
+
3
+
4
+ from argenta.response.entity import Response
5
+ from argenta.response.status import Status