argenta 1.0.0b2__py3-none-any.whl → 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- argenta/app/autocompleter/entity.py +30 -11
- argenta/app/defaults.py +3 -3
- argenta/app/dividing_line/models.py +8 -10
- argenta/app/models.py +181 -114
- argenta/app/registered_routers/entity.py +1 -1
- argenta/command/__init__.py +1 -1
- argenta/command/exceptions.py +9 -2
- argenta/command/flag/defaults.py +17 -10
- argenta/command/flag/models.py +14 -11
- argenta/command/flags/__init__.py +14 -8
- argenta/command/flags/models.py +11 -8
- argenta/command/models.py +61 -36
- argenta/orchestrator/argparser/__init__.py +1 -1
- argenta/orchestrator/argparser/arguments/__init__.py +5 -3
- argenta/orchestrator/argparser/arguments/models.py +3 -2
- argenta/orchestrator/argparser/entity.py +22 -12
- argenta/orchestrator/entity.py +0 -1
- argenta/response/entity.py +13 -11
- argenta/response/status.py +4 -5
- argenta/router/__init__.py +1 -1
- argenta/router/command_handler/entity.py +1 -1
- argenta/router/defaults.py +1 -1
- argenta/router/entity.py +60 -60
- argenta/router/exceptions.py +4 -0
- argenta-1.0.1.dist-info/METADATA +71 -0
- argenta-1.0.1.dist-info/RECORD +37 -0
- argenta-1.0.0b2.dist-info/METADATA +0 -1340
- argenta-1.0.0b2.dist-info/RECORD +0 -37
- {argenta-1.0.0b2.dist-info → argenta-1.0.1.dist-info}/WHEEL +0 -0
- {argenta-1.0.0b2.dist-info → argenta-1.0.1.dist-info}/licenses/LICENSE +0 -0
argenta/router/entity.py
CHANGED
@@ -6,29 +6,33 @@ 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.models import (
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
from argenta.command.flags.models import (
|
10
|
+
Flags,
|
11
|
+
InputFlags,
|
12
|
+
UndefinedInputFlags,
|
13
|
+
ValidInputFlags,
|
14
|
+
InvalidValueInputFlags,
|
15
|
+
)
|
16
|
+
from argenta.router.exceptions import (
|
17
|
+
RepeatedFlagNameException,
|
18
|
+
TooManyTransferredArgsException,
|
19
|
+
RequiredArgumentNotPassedException,
|
20
|
+
TriggerContainSpacesException,
|
21
|
+
)
|
17
22
|
|
18
23
|
|
19
24
|
class Router:
|
20
|
-
def __init__(self, title: str =
|
25
|
+
def __init__(self, title: str | None = "Awesome title"):
|
21
26
|
"""
|
22
27
|
Public. Directly configures and manages handlers
|
23
28
|
:param title: the title of the router, displayed when displaying the available commands
|
24
29
|
:return: None
|
25
30
|
"""
|
26
|
-
self.
|
31
|
+
self.title = title
|
27
32
|
|
28
33
|
self._command_handlers: CommandHandlers = CommandHandlers()
|
29
34
|
self._ignore_command_register: bool = False
|
30
35
|
|
31
|
-
|
32
36
|
def command(self, command: Command | str) -> Callable:
|
33
37
|
"""
|
34
38
|
Public. Registers handler
|
@@ -45,11 +49,11 @@ class Router:
|
|
45
49
|
|
46
50
|
def wrapper(*args, **kwargs):
|
47
51
|
return func(*args, **kwargs)
|
52
|
+
|
48
53
|
return wrapper
|
49
54
|
|
50
55
|
return command_decorator
|
51
56
|
|
52
|
-
|
53
57
|
def finds_appropriate_handler(self, input_command: InputCommand) -> None:
|
54
58
|
"""
|
55
59
|
Private. Finds the appropriate handler for given input command and passes control to it
|
@@ -66,8 +70,9 @@ class Router:
|
|
66
70
|
if input_command_name.lower() in handle_command.get_aliases():
|
67
71
|
self.process_input_command(input_command_flags, command_handler)
|
68
72
|
|
69
|
-
|
70
|
-
|
73
|
+
def process_input_command(
|
74
|
+
self, input_command_flags: InputFlags, command_handler: CommandHandler
|
75
|
+
) -> None:
|
71
76
|
"""
|
72
77
|
Private. Processes input command with the appropriate handler
|
73
78
|
:param input_command_flags: input command flags as InputFlags
|
@@ -78,7 +83,9 @@ class Router:
|
|
78
83
|
response: Response = Response()
|
79
84
|
if handle_command.get_registered_flags().get_flags():
|
80
85
|
if input_command_flags.get_flags():
|
81
|
-
response: Response = self._structuring_input_flags(
|
86
|
+
response: Response = self._structuring_input_flags(
|
87
|
+
handle_command, input_command_flags
|
88
|
+
)
|
82
89
|
command_handler.handling(response)
|
83
90
|
else:
|
84
91
|
response.status = Status.ALL_FLAGS_VALID
|
@@ -93,9 +100,10 @@ class Router:
|
|
93
100
|
response.status = Status.ALL_FLAGS_VALID
|
94
101
|
command_handler.handling(response)
|
95
102
|
|
96
|
-
|
97
103
|
@staticmethod
|
98
|
-
def _structuring_input_flags(
|
104
|
+
def _structuring_input_flags(
|
105
|
+
handled_command: Command, input_flags: InputFlags
|
106
|
+
) -> Response:
|
99
107
|
"""
|
100
108
|
Private. Validates flags of input command
|
101
109
|
:param handled_command: entity of the handled command
|
@@ -106,29 +114,41 @@ class Router:
|
|
106
114
|
invalid_value_input_flags: InvalidValueInputFlags = InvalidValueInputFlags()
|
107
115
|
undefined_input_flags: UndefinedInputFlags = UndefinedInputFlags()
|
108
116
|
for flag in input_flags:
|
109
|
-
flag_status: Literal[
|
117
|
+
flag_status: Literal["Undefined", "Valid", "Invalid"] = (
|
118
|
+
handled_command.validate_input_flag(flag)
|
119
|
+
)
|
110
120
|
match flag_status:
|
111
|
-
case
|
121
|
+
case "Valid":
|
112
122
|
valid_input_flags.add_flag(flag)
|
113
|
-
case
|
123
|
+
case "Undefined":
|
114
124
|
undefined_input_flags.add_flag(flag)
|
115
|
-
case
|
125
|
+
case "Invalid":
|
116
126
|
invalid_value_input_flags.add_flag(flag)
|
117
127
|
|
118
|
-
if
|
128
|
+
if (
|
129
|
+
not invalid_value_input_flags.get_flags()
|
130
|
+
and not undefined_input_flags.get_flags()
|
131
|
+
):
|
119
132
|
status = Status.ALL_FLAGS_VALID
|
120
|
-
elif
|
133
|
+
elif (
|
134
|
+
invalid_value_input_flags.get_flags()
|
135
|
+
and not undefined_input_flags.get_flags()
|
136
|
+
):
|
121
137
|
status = Status.INVALID_VALUE_FLAGS
|
122
|
-
elif
|
138
|
+
elif (
|
139
|
+
not invalid_value_input_flags.get_flags()
|
140
|
+
and undefined_input_flags.get_flags()
|
141
|
+
):
|
123
142
|
status = Status.UNDEFINED_FLAGS
|
124
143
|
else:
|
125
144
|
status = Status.UNDEFINED_AND_INVALID_FLAGS
|
126
145
|
|
127
|
-
return Response(
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
146
|
+
return Response(
|
147
|
+
invalid_value_flags=invalid_value_input_flags,
|
148
|
+
valid_flags=valid_input_flags,
|
149
|
+
status=status,
|
150
|
+
undefined_flags=undefined_input_flags,
|
151
|
+
)
|
132
152
|
|
133
153
|
@staticmethod
|
134
154
|
def _validate_command(command: Command | str) -> None:
|
@@ -138,20 +158,19 @@ class Router:
|
|
138
158
|
:return: None if command is valid else raise exception
|
139
159
|
"""
|
140
160
|
match type(command).__name__:
|
141
|
-
case
|
161
|
+
case "Command":
|
142
162
|
command_name: str = command.get_trigger()
|
143
|
-
if command_name.find(
|
163
|
+
if command_name.find(" ") != -1:
|
144
164
|
raise TriggerContainSpacesException()
|
145
165
|
flags: Flags = command.get_registered_flags()
|
146
166
|
if flags:
|
147
167
|
flags_name: list = [x.get_string_entity().lower() for x in flags]
|
148
168
|
if len(set(flags_name)) < len(flags_name):
|
149
169
|
raise RepeatedFlagNameException()
|
150
|
-
case
|
151
|
-
if command.find(
|
170
|
+
case "str":
|
171
|
+
if command.find(" ") != -1:
|
152
172
|
raise TriggerContainSpacesException()
|
153
173
|
|
154
|
-
|
155
174
|
@staticmethod
|
156
175
|
def _validate_func_args(func: Callable) -> None:
|
157
176
|
"""
|
@@ -173,13 +192,14 @@ class Router:
|
|
173
192
|
pass
|
174
193
|
else:
|
175
194
|
file_path: str = getsourcefile(func)
|
176
|
-
source_line: int = getsourcelines(func)[1]+1
|
195
|
+
source_line: int = getsourcelines(func)[1] + 1
|
177
196
|
fprint = Console().print
|
178
|
-
fprint(
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
197
|
+
fprint(
|
198
|
+
f'\nFile "{file_path}", line {source_line}\n[b red]WARNING:[/b red] [i]The typehint '
|
199
|
+
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
|
+
)
|
183
203
|
|
184
204
|
def set_command_register_ignore(self, _: bool) -> None:
|
185
205
|
"""
|
@@ -189,7 +209,6 @@ class Router:
|
|
189
209
|
"""
|
190
210
|
self._ignore_command_register = _
|
191
211
|
|
192
|
-
|
193
212
|
def get_triggers(self) -> list[str]:
|
194
213
|
"""
|
195
214
|
Public. Gets registered triggers
|
@@ -200,7 +219,6 @@ class Router:
|
|
200
219
|
all_triggers.append(command_handler.get_handled_command().get_trigger())
|
201
220
|
return all_triggers
|
202
221
|
|
203
|
-
|
204
222
|
def get_aliases(self) -> list[str]:
|
205
223
|
"""
|
206
224
|
Public. Gets registered aliases
|
@@ -212,27 +230,9 @@ class Router:
|
|
212
230
|
all_aliases.extend(command_handler.get_handled_command().get_aliases())
|
213
231
|
return all_aliases
|
214
232
|
|
215
|
-
|
216
233
|
def get_command_handlers(self) -> CommandHandlers:
|
217
234
|
"""
|
218
235
|
Private. Gets registered command handlers
|
219
236
|
:return: registered command handlers as CommandHandlers
|
220
237
|
"""
|
221
238
|
return self._command_handlers
|
222
|
-
|
223
|
-
|
224
|
-
def get_title(self) -> str | None:
|
225
|
-
"""
|
226
|
-
Public. Gets title of the router
|
227
|
-
:return: the title of the router as str or None
|
228
|
-
"""
|
229
|
-
return self._title
|
230
|
-
|
231
|
-
|
232
|
-
def set_title(self, title: str) -> None:
|
233
|
-
"""
|
234
|
-
Public. Sets the title of the router
|
235
|
-
:param title: title that will be setted
|
236
|
-
:return: None
|
237
|
-
"""
|
238
|
-
self._title = title
|
argenta/router/exceptions.py
CHANGED
@@ -2,6 +2,7 @@ class RepeatedFlagNameException(Exception):
|
|
2
2
|
"""
|
3
3
|
Private. Raised when a repeated flag name is registered
|
4
4
|
"""
|
5
|
+
|
5
6
|
def __str__(self):
|
6
7
|
return "Repeated registered flag names in register command"
|
7
8
|
|
@@ -10,6 +11,7 @@ class TooManyTransferredArgsException(Exception):
|
|
10
11
|
"""
|
11
12
|
Private. Raised when too many arguments are passed
|
12
13
|
"""
|
14
|
+
|
13
15
|
def __str__(self):
|
14
16
|
return "Too many transferred arguments"
|
15
17
|
|
@@ -18,6 +20,7 @@ class RequiredArgumentNotPassedException(Exception):
|
|
18
20
|
"""
|
19
21
|
Private. Raised when a required argument is not passed
|
20
22
|
"""
|
23
|
+
|
21
24
|
def __str__(self):
|
22
25
|
return "Required argument not passed"
|
23
26
|
|
@@ -26,5 +29,6 @@ class TriggerContainSpacesException(Exception):
|
|
26
29
|
"""
|
27
30
|
Private. Raised when there is a space in the trigger being registered
|
28
31
|
"""
|
32
|
+
|
29
33
|
def __str__(self):
|
30
34
|
return "Command trigger cannot contain spaces"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: argenta
|
3
|
+
Version: 1.0.1
|
4
|
+
Summary: Python library for building modular CLI applications
|
5
|
+
Author-email: kolo <kolo.is.main@gmail.com>
|
6
|
+
License: MIT
|
7
|
+
License-File: LICENSE
|
8
|
+
Requires-Python: <4.0,>=3.11
|
9
|
+
Requires-Dist: art<7.0,>=6.4
|
10
|
+
Requires-Dist: pyreadline3>=3.5.4
|
11
|
+
Requires-Dist: rich<15.0.0,>=14.0.0
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
|
14
|
+
# Argenta
|
15
|
+
|
16
|
+
### Библиотека для создания модульных CLI приложeний
|
17
|
+
|
18
|
+

|
19
|
+
|
20
|
+
---
|
21
|
+
|
22
|
+
# Установка
|
23
|
+
```bash
|
24
|
+
pip install argenta
|
25
|
+
```
|
26
|
+
or
|
27
|
+
```bash
|
28
|
+
poetry add argenta
|
29
|
+
```
|
30
|
+
|
31
|
+
---
|
32
|
+
|
33
|
+
# Быстрый старт
|
34
|
+
|
35
|
+
Пример простейшего приложения
|
36
|
+
```python
|
37
|
+
# routers.py
|
38
|
+
from argenta.router import Router
|
39
|
+
from argenta.command import Command
|
40
|
+
from argenta.response import Response
|
41
|
+
|
42
|
+
|
43
|
+
router = Router()
|
44
|
+
|
45
|
+
@router.command(Command("hello"))
|
46
|
+
def handler(response: Response):
|
47
|
+
print("Hello, world!")
|
48
|
+
```
|
49
|
+
|
50
|
+
```python
|
51
|
+
# main.py
|
52
|
+
from argenta.app import App
|
53
|
+
from argenta.orchestrator import Orchestrator
|
54
|
+
from routers import router
|
55
|
+
|
56
|
+
app: App = App()
|
57
|
+
orchestrator: Orchestrator = Orchestrator()
|
58
|
+
|
59
|
+
|
60
|
+
def main() -> None:
|
61
|
+
app.include_router(router)
|
62
|
+
orchestrator.start_polling(app)
|
63
|
+
|
64
|
+
|
65
|
+
if __name__ == '__main__':
|
66
|
+
main()
|
67
|
+
```
|
68
|
+
## Полная [документация](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
|
69
|
+
|
70
|
+
|
71
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
argenta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
argenta/app/__init__.py,sha256=I8FTXU17ajDI-hbC6Rw0LxLmvDYipdQaos3v1pmu14E,57
|
3
|
+
argenta/app/defaults.py,sha256=z65HUXd1ogTk95-IWwluPDPz4MkZk1_3jfaSjdTZ4ME,393
|
4
|
+
argenta/app/models.py,sha256=yG3IhR9IrEd2YwrtqoZni6wht2rDOyocfoe5SmPv6cw,19153
|
5
|
+
argenta/app/autocompleter/__init__.py,sha256=VT_p3QA78UnczV7pYR2NnwQ0Atd8mnDUnLazvUQNqJk,93
|
6
|
+
argenta/app/autocompleter/entity.py,sha256=QgEZ2Tzfp9liWBCd-BdRpUE-ELUOxAhPpW7KBLVcPRE,3556
|
7
|
+
argenta/app/dividing_line/__init__.py,sha256=jJZDDZix8XYCAUWW4FzGJH0JmJlchYcx0FPWifjgv1I,147
|
8
|
+
argenta/app/dividing_line/models.py,sha256=syBTrzcIIt6E6RiaKC9QH3kdAuWLBDNIX0cH7Bnn0mk,2265
|
9
|
+
argenta/app/registered_routers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
+
argenta/app/registered_routers/entity.py,sha256=OH7plYfjQrlyVliXE6OLVD2ftOAd5U1VO6SlyvLNikk,1078
|
11
|
+
argenta/command/__init__.py,sha256=RvacrM84ZwBdVDy4MUwjLTyzQdDQrjjoikZxwh5ov-0,69
|
12
|
+
argenta/command/exceptions.py,sha256=86Gs_9-NutmbSkduEMljtxQHWHhDRFcqyyOKDhQ440o,1060
|
13
|
+
argenta/command/models.py,sha256=9zzOEJt-jn1ke9HcQGnTOIvNZYrXn347rDzVzm2Ve5Y,7180
|
14
|
+
argenta/command/flag/__init__.py,sha256=4MOxfv8f2SkBzIfVo5LAZUTu4iH1jcs5WzPq60PhFMs,94
|
15
|
+
argenta/command/flag/defaults.py,sha256=1F9bEngv6tB_yn5lLQg5pxWZSuinryfGGdXnWD7EvuY,1035
|
16
|
+
argenta/command/flag/models.py,sha256=KAzyoNWVOVLiIT4f8auI15D0TCHosGXHGw_xXRuEtgY,3875
|
17
|
+
argenta/command/flags/__init__.py,sha256=XFi7_xYjpjnet7FGO93PTcUexeTQ9QwFHuUg_19Ferk,289
|
18
|
+
argenta/command/flags/models.py,sha256=U4nOwCqsCOURGigTKiQx07zBUKj0EoY0fCwgTNq4GIg,2332
|
19
|
+
argenta/orchestrator/__init__.py,sha256=vFtJEJTjFfoYP3DZx0gNlhoa0Tk8u-yzkGIUN3SiABA,86
|
20
|
+
argenta/orchestrator/entity.py,sha256=kgTHGrbWdsTDR7aAKv2Bvm8pO7LKFv7v8Dv1LDsdrTo,1093
|
21
|
+
argenta/orchestrator/argparser/__init__.py,sha256=akbTPC5CfNrgJTVVu1A2E9KeI8KPN4JnMM8M8U21jc8,90
|
22
|
+
argenta/orchestrator/argparser/entity.py,sha256=i3lCsCr_8JT09OosvxRuRD7KKP1MgeNFYz5kTTTqu9Q,2087
|
23
|
+
argenta/orchestrator/argparser/arguments/__init__.py,sha256=lRsKyJeiibPYhFZoeB3BRfIYM4mlUFp6nZpy9RdbgYg,213
|
24
|
+
argenta/orchestrator/argparser/arguments/models.py,sha256=wF4rIaEAx9Rt-c6rAeq6kZLfNPTn4v9WBNt9JHzJ0RA,1548
|
25
|
+
argenta/response/__init__.py,sha256=u4NuwUQkWa55aX67hTQs_B_gIaZ9Dn4Fe7xhSFQ_Rpw,128
|
26
|
+
argenta/response/entity.py,sha256=YcuKLnr7iiFewNqUH7bsdv-PccHfpitq-sm06tmSCjE,1042
|
27
|
+
argenta/response/status.py,sha256=bWFMHvyIHpOA4LxUQFoSpld-F8gu183M9nY-zN-MiZM,244
|
28
|
+
argenta/router/__init__.py,sha256=rvqAx80IXHFdVw7cWBRGaTtb94a4OQQEsMJ5f7YA1gU,68
|
29
|
+
argenta/router/defaults.py,sha256=vvkwFYCQdwjtMntfyrJuisxFX8XxeyhDMA-RwteHZGg,87
|
30
|
+
argenta/router/entity.py,sha256=Z3QZpntlZgt2bkJCb3zUsQ1_a05c61iN59-PBG0r7wg,9656
|
31
|
+
argenta/router/exceptions.py,sha256=5k0mTHYYItWHzGC0NU5oHHYrHxU0M5fEbO5wne_wFg8,860
|
32
|
+
argenta/router/command_handler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
|
+
argenta/router/command_handler/entity.py,sha256=xmHgbXBvD_-JMLpUPc5w3VVe-upTJ-y4lR13rUiiygo,2387
|
34
|
+
argenta-1.0.1.dist-info/METADATA,sha256=IH4CZ1jn49gksobDBswJMcdMqDj7CtGY9-QzeWF2BKY,1448
|
35
|
+
argenta-1.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
36
|
+
argenta-1.0.1.dist-info/licenses/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
|
37
|
+
argenta-1.0.1.dist-info/RECORD,,
|