argenta 0.3.3__tar.gz → 0.3.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.
- {argenta-0.3.3 → argenta-0.3.4}/PKG-INFO +1 -1
- {argenta-0.3.3 → argenta-0.3.4}/argenta/app/entity.py +41 -59
- {argenta-0.3.3 → argenta-0.3.4}/argenta/command/entity.py +6 -1
- {argenta-0.3.3 → argenta-0.3.4}/argenta/command/exceptions.py +4 -14
- {argenta-0.3.3 → argenta-0.3.4}/argenta/command/params/flag/entity.py +1 -0
- {argenta-0.3.3 → argenta-0.3.4}/pyproject.toml +1 -1
- {argenta-0.3.3 → argenta-0.3.4}/LICENSE +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/README.md +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/__init__.py +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/app/__init__.py +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/app/exceptions.py +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/command/__init__.py +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/command/params/__init__.py +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/command/params/flag/__init__.py +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/command/params/flag/flags_group/__init__.py +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/command/params/flag/flags_group/entity.py +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/router/__init__.py +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/router/entity.py +0 -0
- {argenta-0.3.3 → argenta-0.3.4}/argenta/router/exceptions.py +0 -0
@@ -4,11 +4,9 @@ from inspect import getfullargspec
|
|
4
4
|
from ..command.entity import Command
|
5
5
|
from ..router.entity import Router
|
6
6
|
from ..command.exceptions import (UnprocessedInputFlagException,
|
7
|
-
InvalidInputFlagsHandlerHasBeenAlreadyCreatedException,
|
8
7
|
IncorrectNumberOfHandlerArgsException,
|
9
|
-
UnknownCommandHandlerHasBeenAlreadyCreatedException,
|
10
8
|
RepeatedInputFlagsException,
|
11
|
-
|
9
|
+
EmptyInputCommandException)
|
12
10
|
from .exceptions import (InvalidRouterInstanceException,
|
13
11
|
InvalidDescriptionMessagePatternException,
|
14
12
|
NoRegisteredRoutersException,
|
@@ -46,12 +44,12 @@ class App:
|
|
46
44
|
self.repeat_command_groups = repeat_command_groups
|
47
45
|
|
48
46
|
self._routers: list[Router] = []
|
49
|
-
self._invalid_input_flags_handler: Callable[[str], None] | None = None
|
50
|
-
self._repeated_input_flags_handler: Callable[[str], None] | None = None
|
51
|
-
self._unknown_command_handler: Callable[[Command], None] | None = None
|
52
|
-
self._registered_router_entities: list[dict[str, str | list[dict[str, Callable[[], None] | Command]] | Router]] = []
|
53
|
-
self._app_main_router: Router | None = None
|
54
47
|
self._description_message_pattern: str = '[{command}] *=*=* {description}'
|
48
|
+
self._registered_router_entities: list[dict[str, str | list[dict[str, Callable[[], None] | Command]] | Router]] = []
|
49
|
+
self._invalid_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Incorrect flag syntax: "{raw_command}"')
|
50
|
+
self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: "{raw_command}"')
|
51
|
+
self._empty_input_command_handler: Callable[[], None] = lambda: print_func(f'Empty input command')
|
52
|
+
self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_string_entity()}")
|
55
53
|
|
56
54
|
|
57
55
|
def start_polling(self) -> None:
|
@@ -76,31 +74,39 @@ class App:
|
|
76
74
|
input_command: Command = Command.parse_input_command(raw_command=raw_command)
|
77
75
|
except UnprocessedInputFlagException:
|
78
76
|
self.print_func(self.line_separate)
|
79
|
-
|
80
|
-
self._invalid_input_flags_handler(raw_command)
|
81
|
-
else:
|
82
|
-
self.print_func(f'Incorrect flag syntax: "{raw_command}"')
|
77
|
+
self._invalid_input_flags_handler(raw_command)
|
83
78
|
self.print_func(self.line_separate)
|
79
|
+
|
84
80
|
if not self.repeat_command_groups:
|
85
81
|
self.print_func(self.prompt)
|
86
82
|
continue
|
83
|
+
|
87
84
|
except RepeatedInputFlagsException:
|
88
85
|
self.print_func(self.line_separate)
|
89
|
-
|
90
|
-
self._repeated_input_flags_handler(raw_command)
|
91
|
-
else:
|
92
|
-
self.print_func(f'Repeated input flags: "{raw_command}"')
|
86
|
+
self._repeated_input_flags_handler(raw_command)
|
93
87
|
self.print_func(self.line_separate)
|
88
|
+
|
94
89
|
if not self.repeat_command_groups:
|
95
90
|
self.print_func(self.prompt)
|
96
91
|
continue
|
97
92
|
|
98
|
-
|
99
|
-
|
93
|
+
except EmptyInputCommandException:
|
94
|
+
self.print_func(self.line_separate)
|
95
|
+
self._empty_input_command_handler()
|
96
|
+
self.print_func(self.line_separate)
|
100
97
|
|
98
|
+
if not self.repeat_command_groups:
|
99
|
+
self.print_func(self.prompt)
|
100
|
+
continue
|
101
|
+
|
102
|
+
self._check_command_for_exit_command(input_command.get_string_entity())
|
103
|
+
|
104
|
+
self.print_func(self.line_separate)
|
101
105
|
is_unknown_command: bool = self._check_is_command_unknown(input_command)
|
102
106
|
|
103
107
|
if is_unknown_command:
|
108
|
+
self.print_func(self.line_separate)
|
109
|
+
self.print_func(self.command_group_description_separate)
|
104
110
|
if not self.repeat_command_groups:
|
105
111
|
self.print_func(self.prompt)
|
106
112
|
continue
|
@@ -124,52 +130,35 @@ class App:
|
|
124
130
|
|
125
131
|
def set_description_message_pattern(self, pattern: str) -> None:
|
126
132
|
try:
|
127
|
-
pattern.format(command='command',
|
128
|
-
description='description')
|
133
|
+
pattern.format(command='command', description='description')
|
129
134
|
except KeyError:
|
130
135
|
raise InvalidDescriptionMessagePatternException(pattern)
|
131
|
-
|
136
|
+
else:
|
137
|
+
self._description_message_pattern: str = pattern
|
132
138
|
|
133
139
|
|
134
140
|
def set_invalid_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
135
|
-
|
136
|
-
|
141
|
+
args = getfullargspec(handler).args
|
142
|
+
if len(args) != 1:
|
143
|
+
raise IncorrectNumberOfHandlerArgsException()
|
137
144
|
else:
|
138
|
-
|
139
|
-
if len(args) != 1:
|
140
|
-
raise IncorrectNumberOfHandlerArgsException()
|
141
|
-
else:
|
142
|
-
self._invalid_input_flags_handler = handler
|
145
|
+
self._invalid_input_flags_handler = handler
|
143
146
|
|
144
147
|
|
145
148
|
def set_repeated_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
146
|
-
|
147
|
-
|
149
|
+
args = getfullargspec(handler).args
|
150
|
+
if len(args) != 1:
|
151
|
+
raise IncorrectNumberOfHandlerArgsException()
|
148
152
|
else:
|
149
|
-
|
150
|
-
if len(args) != 1:
|
151
|
-
raise IncorrectNumberOfHandlerArgsException()
|
152
|
-
else:
|
153
|
-
self._repeated_input_flags_handler = handler
|
153
|
+
self._repeated_input_flags_handler = handler
|
154
154
|
|
155
155
|
|
156
156
|
def set_unknown_command_handler(self, handler: Callable[[str], None]) -> None:
|
157
|
-
|
158
|
-
|
157
|
+
args = getfullargspec(handler).args
|
158
|
+
if len(args) != 1:
|
159
|
+
raise IncorrectNumberOfHandlerArgsException()
|
159
160
|
else:
|
160
|
-
|
161
|
-
if len(args) != 1:
|
162
|
-
raise IncorrectNumberOfHandlerArgsException()
|
163
|
-
else:
|
164
|
-
self._unknown_command_handler = handler
|
165
|
-
|
166
|
-
|
167
|
-
def get_all_app_commands(self) -> list[str]:
|
168
|
-
all_commands: list[str] = []
|
169
|
-
for router in self._routers:
|
170
|
-
all_commands.extend(router.get_all_commands())
|
171
|
-
|
172
|
-
return all_commands
|
161
|
+
self._unknown_command_handler = handler
|
173
162
|
|
174
163
|
|
175
164
|
def include_router(self, router: Router) -> None:
|
@@ -213,7 +202,7 @@ class App:
|
|
213
202
|
raise RepeatedCommandInDifferentRoutersException()
|
214
203
|
|
215
204
|
|
216
|
-
def
|
205
|
+
def _check_command_for_exit_command(self, command: str):
|
217
206
|
if command.lower() == self.exit_command.lower():
|
218
207
|
if self.ignore_exit_command_register:
|
219
208
|
self.print_func(self.farewell_message)
|
@@ -234,14 +223,7 @@ class App:
|
|
234
223
|
else:
|
235
224
|
if command_entity['command'].get_string_entity() == command.get_string_entity():
|
236
225
|
return False
|
237
|
-
|
238
|
-
if self._unknown_command_handler:
|
239
|
-
self._unknown_command_handler(command)
|
240
|
-
else:
|
241
|
-
print(f"Unknown command: {command.get_string_entity()}")
|
242
|
-
|
243
|
-
self.print_func(self.line_separate)
|
244
|
-
self.print_func(self.command_group_description_separate)
|
226
|
+
self._unknown_command_handler(command)
|
245
227
|
return True
|
246
228
|
|
247
229
|
|
@@ -2,7 +2,10 @@ from .params.flag.entity import Flag
|
|
2
2
|
from .params.flag.flags_group.entity import FlagsGroup
|
3
3
|
from .exceptions import (InvalidCommandInstanceException,
|
4
4
|
InvalidDescriptionInstanceException,
|
5
|
-
InvalidFlagsInstanceException,
|
5
|
+
InvalidFlagsInstanceException,
|
6
|
+
UnprocessedInputFlagException,
|
7
|
+
RepeatedInputFlagsException,
|
8
|
+
EmptyInputCommandException)
|
6
9
|
|
7
10
|
from typing import Generic, TypeVar
|
8
11
|
|
@@ -71,6 +74,8 @@ class Command(Generic[T]):
|
|
71
74
|
|
72
75
|
@staticmethod
|
73
76
|
def parse_input_command(raw_command: str) -> 'Command[T]':
|
77
|
+
if not raw_command:
|
78
|
+
raise EmptyInputCommandException()
|
74
79
|
list_of_tokens = raw_command.split()
|
75
80
|
command = list_of_tokens[0]
|
76
81
|
list_of_tokens.pop(0)
|
@@ -29,21 +29,11 @@ class RepeatedInputFlagsException(Exception):
|
|
29
29
|
f"Duplicate flag was detected in the input: '{self.flag.get_string_entity()}'")
|
30
30
|
|
31
31
|
|
32
|
-
class
|
33
|
-
def __str__(self):
|
34
|
-
return "Invalid Input Flags Handler has already been created"
|
35
|
-
|
36
|
-
|
37
|
-
class RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException(Exception):
|
38
|
-
def __str__(self):
|
39
|
-
return "Repeated Input Flags Handler has already been created"
|
40
|
-
|
41
|
-
|
42
|
-
class UnknownCommandHandlerHasBeenAlreadyCreatedException(Exception):
|
32
|
+
class IncorrectNumberOfHandlerArgsException(Exception):
|
43
33
|
def __str__(self):
|
44
|
-
return "
|
34
|
+
return "Incorrect Input Flags Handler has incorrect number of arguments"
|
45
35
|
|
46
36
|
|
47
|
-
class
|
37
|
+
class EmptyInputCommandException(Exception):
|
48
38
|
def __str__(self):
|
49
|
-
return "
|
39
|
+
return "Input Command is empty"
|
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
|