argenta 1.0.0b1__py3-none-any.whl → 1.0.0b2__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/models.py +2 -2
- argenta/command/flag/models.py +6 -0
- argenta/command/flags/models.py +12 -0
- argenta/command/models.py +1 -1
- argenta/response/entity.py +8 -1
- argenta/router/entity.py +42 -26
- {argenta-1.0.0b1.dist-info → argenta-1.0.0b2.dist-info}/METADATA +3 -3
- {argenta-1.0.0b1.dist-info → argenta-1.0.0b2.dist-info}/RECORD +10 -10
- {argenta-1.0.0b1.dist-info → argenta-1.0.0b2.dist-info}/WHEEL +0 -0
- {argenta-1.0.0b1.dist-info → argenta-1.0.0b2.dist-info}/licenses/LICENSE +0 -0
argenta/app/models.py
CHANGED
@@ -238,7 +238,7 @@ class BaseApp:
|
|
238
238
|
:return: None
|
239
239
|
"""
|
240
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
|
241
|
+
self._initial_message = f'\n[bold red]{text2art(self._initial_message, font="tarty1")}\n'
|
242
242
|
self._farewell_message = (f'[bold red]\n{text2art(f"\n{self._farewell_message}\n", font="chanky")}[/bold red]\n'
|
243
243
|
f'[red i]github.com/koloideal/Argenta[/red i] | [red bold i]made by kolo[/red bold i]\n')
|
244
244
|
self._description_message_gen = lambda command, description: (f'[bold red]{escape("[" + command + "]")}[/bold red] '
|
@@ -282,7 +282,7 @@ class BaseApp:
|
|
282
282
|
for message in self._messages_on_startup:
|
283
283
|
self._print_func(message)
|
284
284
|
if self._messages_on_startup:
|
285
|
-
print('\n
|
285
|
+
print('\n')
|
286
286
|
|
287
287
|
if not self._repeat_command_groups_description:
|
288
288
|
self._print_command_group_description()
|
argenta/command/flag/models.py
CHANGED
@@ -36,6 +36,9 @@ class BaseFlag:
|
|
36
36
|
"""
|
37
37
|
return self._prefix
|
38
38
|
|
39
|
+
def __eq__(self, other) -> bool:
|
40
|
+
return self.get_string_entity() == other.get_string_entity()
|
41
|
+
|
39
42
|
|
40
43
|
class Flag(BaseFlag):
|
41
44
|
def __init__(self, name: str,
|
@@ -110,3 +113,6 @@ class InputFlag(BaseFlag):
|
|
110
113
|
"""
|
111
114
|
self._flag_value = value
|
112
115
|
|
116
|
+
def __eq__(self, other) -> bool:
|
117
|
+
return self.get_string_entity() == other.get_string_entity() and self.get_value() == other.get_value()
|
118
|
+
|
argenta/command/flags/models.py
CHANGED
@@ -58,6 +58,18 @@ class BaseFlags(Generic[FlagType]):
|
|
58
58
|
def __getitem__(self, item):
|
59
59
|
return self._flags[item]
|
60
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
|
+
|
61
73
|
|
62
74
|
class Flags(BaseFlags[Flag]): pass
|
63
75
|
|
argenta/command/models.py
CHANGED
@@ -39,7 +39,7 @@ class Command(BaseCommand):
|
|
39
39
|
"""
|
40
40
|
super().__init__(trigger)
|
41
41
|
self._registered_flags: Flags = flags if isinstance(flags, Flags) else Flags(flags) if isinstance(flags, Flag) else Flags()
|
42
|
-
self._description = f'
|
42
|
+
self._description = f'Very useful command' if not description else description
|
43
43
|
self._aliases = aliases if isinstance(aliases, list) else []
|
44
44
|
|
45
45
|
def get_registered_flags(self) -> Flags:
|
argenta/response/entity.py
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
-
from argenta.command.flags.models import ValidInputFlags, UndefinedInputFlags, InvalidValueInputFlags
|
2
1
|
from argenta.response.status import Status
|
2
|
+
from argenta.command.flags import (ValidInputFlags,
|
3
|
+
UndefinedInputFlags,
|
4
|
+
InvalidValueInputFlags)
|
3
5
|
|
4
6
|
|
5
7
|
class Response:
|
8
|
+
__slots__ = ('status',
|
9
|
+
'valid_flags',
|
10
|
+
'undefined_flags',
|
11
|
+
'invalid_value_flags')
|
12
|
+
|
6
13
|
def __init__(self, status: Status = None,
|
7
14
|
valid_flags: ValidInputFlags = ValidInputFlags(),
|
8
15
|
undefined_flags: UndefinedInputFlags = UndefinedInputFlags(),
|
argenta/router/entity.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
from typing import Callable, Literal, Type
|
2
|
-
from inspect import getfullargspec, get_annotations
|
2
|
+
from inspect import getfullargspec, get_annotations, getsourcefile, getsourcelines
|
3
3
|
from rich.console import Console
|
4
4
|
|
5
5
|
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 Flags, InputFlags,
|
9
|
+
from argenta.command.flags.models import (Flags, InputFlags,
|
10
|
+
UndefinedInputFlags,
|
11
|
+
ValidInputFlags,
|
12
|
+
InvalidValueInputFlags)
|
10
13
|
from argenta.router.exceptions import (RepeatedFlagNameException,
|
11
14
|
TooManyTransferredArgsException,
|
12
15
|
RequiredArgumentNotPassedException,
|
@@ -26,13 +29,15 @@ class Router:
|
|
26
29
|
self._ignore_command_register: bool = False
|
27
30
|
|
28
31
|
|
29
|
-
def command(self, command: Command) -> Callable:
|
32
|
+
def command(self, command: Command | str) -> Callable:
|
30
33
|
"""
|
31
34
|
Public. Registers handler
|
32
35
|
:param command: Registered command
|
33
36
|
:return: decorated handler as Callable
|
34
37
|
"""
|
35
38
|
self._validate_command(command)
|
39
|
+
if isinstance(command, str):
|
40
|
+
command = Command(command)
|
36
41
|
|
37
42
|
def command_decorator(func):
|
38
43
|
Router._validate_func_args(func)
|
@@ -73,9 +78,7 @@ class Router:
|
|
73
78
|
response: Response = Response()
|
74
79
|
if handle_command.get_registered_flags().get_flags():
|
75
80
|
if input_command_flags.get_flags():
|
76
|
-
|
77
|
-
response.valid_flags, response.undefined_flags, response.invalid_value_flags = flags
|
78
|
-
response.status = status
|
81
|
+
response: Response = self._structuring_input_flags(handle_command, input_command_flags)
|
79
82
|
command_handler.handling(response)
|
80
83
|
else:
|
81
84
|
response.status = Status.ALL_FLAGS_VALID
|
@@ -92,15 +95,12 @@ class Router:
|
|
92
95
|
|
93
96
|
|
94
97
|
@staticmethod
|
95
|
-
def
|
96
|
-
UndefinedInputFlags,
|
97
|
-
InvalidValueInputFlags],
|
98
|
-
Status]:
|
98
|
+
def _structuring_input_flags(handled_command: Command, input_flags: InputFlags) -> Response:
|
99
99
|
"""
|
100
100
|
Private. Validates flags of input command
|
101
101
|
:param handled_command: entity of the handled command
|
102
102
|
:param input_flags:
|
103
|
-
:return:
|
103
|
+
:return: entity of response as Response
|
104
104
|
"""
|
105
105
|
valid_input_flags: ValidInputFlags = ValidInputFlags()
|
106
106
|
invalid_value_input_flags: InvalidValueInputFlags = InvalidValueInputFlags()
|
@@ -124,25 +124,32 @@ class Router:
|
|
124
124
|
else:
|
125
125
|
status = Status.UNDEFINED_AND_INVALID_FLAGS
|
126
126
|
|
127
|
-
return (
|
127
|
+
return Response(invalid_value_flags=invalid_value_input_flags,
|
128
|
+
valid_flags=valid_input_flags,
|
129
|
+
status=status,
|
130
|
+
undefined_flags=undefined_input_flags)
|
128
131
|
|
129
132
|
|
130
133
|
@staticmethod
|
131
|
-
def _validate_command(command: Command) -> None:
|
134
|
+
def _validate_command(command: Command | str) -> None:
|
132
135
|
"""
|
133
136
|
Private. Validates the command registered in handler
|
134
137
|
:param command: validated command
|
135
138
|
:return: None if command is valid else raise exception
|
136
139
|
"""
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
140
|
+
match type(command).__name__:
|
141
|
+
case 'Command':
|
142
|
+
command_name: str = command.get_trigger()
|
143
|
+
if command_name.find(' ') != -1:
|
144
|
+
raise TriggerContainSpacesException()
|
145
|
+
flags: Flags = command.get_registered_flags()
|
146
|
+
if flags:
|
147
|
+
flags_name: list = [x.get_string_entity().lower() for x in flags]
|
148
|
+
if len(set(flags_name)) < len(flags_name):
|
149
|
+
raise RepeatedFlagNameException()
|
150
|
+
case 'str':
|
151
|
+
if command.find(' ') != -1:
|
152
|
+
raise TriggerContainSpacesException()
|
146
153
|
|
147
154
|
|
148
155
|
@staticmethod
|
@@ -158,10 +165,19 @@ class Router:
|
|
158
165
|
elif len(transferred_args) == 0:
|
159
166
|
raise RequiredArgumentNotPassedException()
|
160
167
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
168
|
+
transferred_arg: str = transferred_args[0]
|
169
|
+
func_annotations: dict[str, Type] = get_annotations(func)
|
170
|
+
|
171
|
+
if arg_annotation := func_annotations.get(transferred_arg):
|
172
|
+
if arg_annotation is Response:
|
173
|
+
pass
|
174
|
+
else:
|
175
|
+
file_path: str = getsourcefile(func)
|
176
|
+
source_line: int = getsourcelines(func)[1]+1
|
177
|
+
fprint = Console().print
|
178
|
+
fprint(f'\nFile "{file_path}", line {source_line}\n[b red]WARNING:[/b red] [i]The typehint '
|
179
|
+
f'of argument([green]{transferred_arg}[/green]) passed to the handler is [/i][bold blue]{Response}[/bold blue],'
|
180
|
+
f' [i]but[/i] [bold blue]{arg_annotation}[/bold blue] [i]is specified[/i]\n', highlight=False)
|
165
181
|
|
166
182
|
|
167
183
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: argenta
|
3
|
-
Version: 1.0.
|
4
|
-
Summary: Python library for
|
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
|
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
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
argenta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
argenta/app/__init__.py,sha256=I8FTXU17ajDI-hbC6Rw0LxLmvDYipdQaos3v1pmu14E,57
|
3
3
|
argenta/app/defaults.py,sha256=GE4UzsJ7PD7654weNzTFGcBroc_0Zy5H9VL5P8ZbFek,393
|
4
|
-
argenta/app/models.py,sha256=
|
4
|
+
argenta/app/models.py,sha256=52iXVPQ7ekL5T60ErDR1X-qCmIt8YjzRerd_L8Jkwxo,18246
|
5
5
|
argenta/app/autocompleter/__init__.py,sha256=VT_p3QA78UnczV7pYR2NnwQ0Atd8mnDUnLazvUQNqJk,93
|
6
6
|
argenta/app/autocompleter/entity.py,sha256=6IurcSTLfiEYrh-yYsCYjrKsJ8_9xds3fxs5sr0FoqE,2901
|
7
7
|
argenta/app/dividing_line/__init__.py,sha256=jJZDDZix8XYCAUWW4FzGJH0JmJlchYcx0FPWifjgv1I,147
|
@@ -10,12 +10,12 @@ argenta/app/registered_routers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5
|
|
10
10
|
argenta/app/registered_routers/entity.py,sha256=hNaY3YfCp62Dk3U1XGvqTjt8mYDzgXcMsgNJMAqIU4w,1076
|
11
11
|
argenta/command/__init__.py,sha256=Plo2Da0fhq8H1eo2mg7nA1-OBLuGjK2BYpDGRvGGMIU,67
|
12
12
|
argenta/command/exceptions.py,sha256=QvJl3fY3MxDZscQQKSQ__lRuP9Jd2XVdQOo27TvmVnw,1030
|
13
|
-
argenta/command/models.py,sha256=
|
13
|
+
argenta/command/models.py,sha256=t_NTLc5CIhV210R-GGb9sQyAb3n51XHx9VIQ9KOq2GI,6914
|
14
14
|
argenta/command/flag/__init__.py,sha256=4MOxfv8f2SkBzIfVo5LAZUTu4iH1jcs5WzPq60PhFMs,94
|
15
15
|
argenta/command/flag/defaults.py,sha256=0wCvh2l3eNU3vTuxuARVaUwhEzG3v9FID0rBbXHyK-k,982
|
16
|
-
argenta/command/flag/models.py,sha256=
|
16
|
+
argenta/command/flag/models.py,sha256=SUXDZPEcy7HTboociW6FFQ7bk0gTfwdt39HRx3AxTCo,3870
|
17
17
|
argenta/command/flags/__init__.py,sha256=Hpw8RO2_RxdRhS8EqWPGuLwAlmRLA-XkbO7q1iNxrvQ,396
|
18
|
-
argenta/command/flags/models.py,sha256=
|
18
|
+
argenta/command/flags/models.py,sha256=nkrM9dwrS--_pbpt7n2UEuOPX0QLwJ263_UK0QA85AA,2311
|
19
19
|
argenta/orchestrator/__init__.py,sha256=vFtJEJTjFfoYP3DZx0gNlhoa0Tk8u-yzkGIUN3SiABA,86
|
20
20
|
argenta/orchestrator/entity.py,sha256=HUKhoEQtiWvxeA3QhSkvTcIgwgXDLjmcB2cBFHlCGhw,1101
|
21
21
|
argenta/orchestrator/argparser/__init__.py,sha256=twfb-FQqW4QUo2XkmMASi654KGiimIbrkEzb1ZkMGzU,88
|
@@ -23,15 +23,15 @@ argenta/orchestrator/argparser/entity.py,sha256=nmwp7dFHTIqLvR9v0n_4j9wvtTowvLK7
|
|
23
23
|
argenta/orchestrator/argparser/arguments/__init__.py,sha256=4T55Tl_4WKOYp9HtVDmzQZylYVKA_cb3XiGoBvAyjNo,318
|
24
24
|
argenta/orchestrator/argparser/arguments/models.py,sha256=hSUXBjTsyzNKvyPgWhiNCa4SSQdmixIQnne2A9iuPMc,1546
|
25
25
|
argenta/response/__init__.py,sha256=u4NuwUQkWa55aX67hTQs_B_gIaZ9Dn4Fe7xhSFQ_Rpw,128
|
26
|
-
argenta/response/entity.py,sha256=
|
26
|
+
argenta/response/entity.py,sha256=Wz-plcx0lDx_VbFQs2I98uxxthZaZ1Gg5YSKfmiwGOQ,1150
|
27
27
|
argenta/response/status.py,sha256=owDBpCrJ0Xb6U5RtvYt9HTdM8ouVgJLFdzVD8h-Ho4w,246
|
28
28
|
argenta/router/__init__.py,sha256=ldrIWTXNLXUAMAGQ8ex4e8nMso_fhi01nZi2DVzHnnk,66
|
29
29
|
argenta/router/defaults.py,sha256=RX3DMbZk7XUbj6uR4uADhZOPqEDoeCz9X-n26YTCCPM,87
|
30
|
-
argenta/router/entity.py,sha256=
|
30
|
+
argenta/router/entity.py,sha256=D7wnWSJ1c5hJzfKp3hdTf5AZMMQZ3z82II5lQn6aie4,10005
|
31
31
|
argenta/router/exceptions.py,sha256=q6y-4gmbgkX-0U4-qXHDP5HTtUQ_c4svaqVILn-ZzRw,852
|
32
32
|
argenta/router/command_handler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
33
|
argenta/router/command_handler/entity.py,sha256=z7X70yD66hAVug0Q-YKPxTLvYOZrLI6qZnPdFLCNmIQ,2385
|
34
|
-
argenta-1.0.
|
35
|
-
argenta-1.0.
|
36
|
-
argenta-1.0.
|
37
|
-
argenta-1.0.
|
34
|
+
argenta-1.0.0b2.dist-info/METADATA,sha256=tAv_oL7bAlFnbqNHx-EU7TKukqloade0HsGDkQnAlgg,25737
|
35
|
+
argenta-1.0.0b2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
36
|
+
argenta-1.0.0b2.dist-info/licenses/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
|
37
|
+
argenta-1.0.0b2.dist-info/RECORD,,
|
File without changes
|
File without changes
|