argenta 0.3.9__py3-none-any.whl → 0.4.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/entity.py +45 -22
- argenta/command/entity.py +3 -3
- argenta/command/flag/defaults.py +13 -10
- argenta/command/flag/flags_group/entity.py +1 -1
- argenta/router/defaults.py +5 -0
- argenta/router/entity.py +5 -1
- {argenta-0.3.9.dist-info → argenta-0.4.1.dist-info}/METADATA +10 -11
- {argenta-0.3.9.dist-info → argenta-0.4.1.dist-info}/RECORD +10 -9
- {argenta-0.3.9.dist-info → argenta-0.4.1.dist-info}/WHEEL +1 -1
- {argenta-0.3.9.dist-info → argenta-0.4.1.dist-info}/LICENSE +0 -0
argenta/app/entity.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
from pprint import pprint
|
2
1
|
from typing import Callable
|
3
2
|
from inspect import getfullargspec
|
4
3
|
import re
|
5
4
|
|
6
|
-
from
|
7
|
-
from
|
8
|
-
from
|
5
|
+
from argenta.command import Command
|
6
|
+
from argenta.router import Router
|
7
|
+
from argenta.router.defaults import system_router
|
8
|
+
from argenta.command.exceptions import (UnprocessedInputFlagException,
|
9
9
|
RepeatedInputFlagsException,
|
10
10
|
EmptyInputCommandException)
|
11
11
|
from .exceptions import (InvalidRouterInstanceException,
|
@@ -30,6 +30,7 @@ class App:
|
|
30
30
|
line_separate: str = '',
|
31
31
|
command_group_description_separate: str = '',
|
32
32
|
repeat_command_groups: bool = True,
|
33
|
+
messages_on_startup: list[str] = None,
|
33
34
|
print_func: Callable[[str], None] = print) -> None:
|
34
35
|
self.prompt = prompt
|
35
36
|
self.print_func = print_func
|
@@ -44,6 +45,7 @@ class App:
|
|
44
45
|
self.command_group_description_separate = command_group_description_separate
|
45
46
|
self.ignore_command_register = ignore_command_register
|
46
47
|
self.repeat_command_groups = repeat_command_groups
|
48
|
+
self.messages_on_startup = messages_on_startup if messages_on_startup else []
|
47
49
|
|
48
50
|
self._routers: list[Router] = []
|
49
51
|
self._description_message_pattern: str = '[{command}] *=*=* {description}'
|
@@ -51,16 +53,21 @@ class App:
|
|
51
53
|
self._invalid_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Incorrect flag syntax: "{raw_command}"')
|
52
54
|
self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: "{raw_command}"')
|
53
55
|
self._empty_input_command_handler: Callable[[], None] = lambda: print_func(f'Empty input command')
|
54
|
-
self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.
|
56
|
+
self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_trigger()}")
|
57
|
+
self._exit_command_handler: Callable[[], None] = lambda: print_func(self.farewell_message)
|
55
58
|
|
56
59
|
|
57
60
|
def start_polling(self) -> None:
|
61
|
+
self._setup_system_router()
|
58
62
|
self._validate_number_of_routers()
|
59
63
|
self._validate_included_routers()
|
60
64
|
self._validate_all_router_commands()
|
61
65
|
|
62
66
|
self.print_func(self.initial_message)
|
63
67
|
|
68
|
+
for message in self.messages_on_startup:
|
69
|
+
self.print_func(message)
|
70
|
+
|
64
71
|
if not self.repeat_command_groups:
|
65
72
|
self._print_command_group_description()
|
66
73
|
self.print_func(self.prompt)
|
@@ -101,7 +108,9 @@ class App:
|
|
101
108
|
self.print_func(self.prompt)
|
102
109
|
continue
|
103
110
|
|
104
|
-
self.
|
111
|
+
is_exit = self._is_exit_command(input_command)
|
112
|
+
if is_exit:
|
113
|
+
return
|
105
114
|
|
106
115
|
self.print_func(self.line_separate)
|
107
116
|
is_unknown_command: bool = self._check_is_command_unknown(input_command)
|
@@ -172,6 +181,18 @@ class App:
|
|
172
181
|
self._empty_input_command_handler = handler
|
173
182
|
|
174
183
|
|
184
|
+
def set_exit_command_handler(self, handler: Callable[[], None]) -> None:
|
185
|
+
args = getfullargspec(handler).args
|
186
|
+
if len(args) != 0:
|
187
|
+
raise IncorrectNumberOfHandlerArgsException()
|
188
|
+
else:
|
189
|
+
self._exit_command_handler = handler
|
190
|
+
|
191
|
+
|
192
|
+
def add_message_on_startup(self, message: str) -> None:
|
193
|
+
self.messages_on_startup.append(message)
|
194
|
+
|
195
|
+
|
175
196
|
def include_router(self, router: Router) -> None:
|
176
197
|
if not isinstance(router, Router):
|
177
198
|
raise InvalidRouterInstanceException()
|
@@ -213,15 +234,26 @@ class App:
|
|
213
234
|
raise RepeatedCommandInDifferentRoutersException()
|
214
235
|
|
215
236
|
|
216
|
-
def
|
217
|
-
|
237
|
+
def _setup_system_router(self):
|
238
|
+
system_router.set_title(self.system_points_title)
|
239
|
+
@system_router.command(Command(self.exit_command, self.exit_command_description))
|
240
|
+
def exit_command():
|
241
|
+
self._exit_command_handler()
|
242
|
+
|
243
|
+
if system_router not in [router['entity'] for router in self._registered_router_entities]:
|
244
|
+
self.include_router(system_router)
|
245
|
+
|
246
|
+
|
247
|
+
def _is_exit_command(self, command: Command):
|
248
|
+
if command.get_trigger().lower() == self.exit_command.lower():
|
218
249
|
if self.ignore_exit_command_register:
|
219
|
-
|
220
|
-
|
250
|
+
system_router.input_command_handler(command)
|
251
|
+
return True
|
221
252
|
else:
|
222
|
-
if command == self.exit_command:
|
223
|
-
|
224
|
-
|
253
|
+
if command.get_trigger() == self.exit_command:
|
254
|
+
system_router.input_command_handler(command)
|
255
|
+
return True
|
256
|
+
return False
|
225
257
|
|
226
258
|
|
227
259
|
def _check_is_command_unknown(self, command: Command):
|
@@ -248,12 +280,3 @@ class App:
|
|
248
280
|
)
|
249
281
|
)
|
250
282
|
self.print_func(self.command_group_description_separate)
|
251
|
-
|
252
|
-
self.print_func(self.system_points_title)
|
253
|
-
self.print_func(self._description_message_pattern.format(
|
254
|
-
command=self.exit_command,
|
255
|
-
description=self.exit_command_description
|
256
|
-
)
|
257
|
-
)
|
258
|
-
self.print_func(self.command_group_description_separate)
|
259
|
-
|
argenta/command/entity.py
CHANGED
@@ -6,6 +6,7 @@ from .exceptions import (UnprocessedInputFlagException,
|
|
6
6
|
|
7
7
|
from typing import Generic, TypeVar, cast, Literal
|
8
8
|
|
9
|
+
|
9
10
|
CommandType = TypeVar('CommandType')
|
10
11
|
|
11
12
|
|
@@ -15,8 +16,7 @@ class Command(Generic[CommandType]):
|
|
15
16
|
flags: Flag | FlagsGroup = None):
|
16
17
|
self._trigger = trigger
|
17
18
|
self._description = f'description for "{self._trigger}" command' if not description else description
|
18
|
-
self._registered_flags: FlagsGroup | None = flags if isinstance(flags, FlagsGroup) else FlagsGroup(
|
19
|
-
|
19
|
+
self._registered_flags: FlagsGroup | None = flags if isinstance(flags, FlagsGroup) else FlagsGroup(flags) if isinstance(flags, Flag) else flags
|
20
20
|
self._input_flags: FlagsGroup | None = None
|
21
21
|
|
22
22
|
|
@@ -56,7 +56,7 @@ class Command(Generic[CommandType]):
|
|
56
56
|
return self._input_flags
|
57
57
|
|
58
58
|
@staticmethod
|
59
|
-
def parse_input_command(raw_command: str) ->
|
59
|
+
def parse_input_command(raw_command: str) -> CommandType:
|
60
60
|
if not raw_command:
|
61
61
|
raise EmptyInputCommandException()
|
62
62
|
list_of_tokens = raw_command.split()
|
argenta/command/flag/defaults.py
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
+
from dataclasses import dataclass
|
1
2
|
from argenta.command.flag import Flag
|
2
3
|
import re
|
3
4
|
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
@dataclass
|
7
|
+
class DefaultFlags:
|
8
|
+
help_flag = Flag(flag_name='help', possible_flag_values=False)
|
9
|
+
short_help_flag = Flag(flag_name='h', flag_prefix='-', possible_flag_values=False)
|
7
10
|
|
8
|
-
info_flag = Flag(flag_name='info', possible_flag_values=False)
|
9
|
-
short_info_flag = Flag(flag_name='i', flag_prefix='-', possible_flag_values=False)
|
11
|
+
info_flag = Flag(flag_name='info', possible_flag_values=False)
|
12
|
+
short_info_flag = Flag(flag_name='i', flag_prefix='-', possible_flag_values=False)
|
10
13
|
|
11
|
-
all_flag = Flag(flag_name='all', possible_flag_values=False)
|
12
|
-
short_all_flag = Flag(flag_name='a', flag_prefix='-', possible_flag_values=False)
|
14
|
+
all_flag = Flag(flag_name='all', possible_flag_values=False)
|
15
|
+
short_all_flag = Flag(flag_name='a', flag_prefix='-', possible_flag_values=False)
|
13
16
|
|
14
|
-
host_flag = Flag(flag_name='host', possible_flag_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
|
15
|
-
short_host_flag = Flag(flag_name='h', flag_prefix='-', possible_flag_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
|
17
|
+
host_flag = Flag(flag_name='host', possible_flag_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
|
18
|
+
short_host_flag = Flag(flag_name='h', flag_prefix='-', possible_flag_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
|
16
19
|
|
17
|
-
port_flag = Flag(flag_name='port', possible_flag_values=re.compile(r'^\d{1,5}$'))
|
18
|
-
short_port_flag = Flag(flag_name='p', flag_prefix='-', possible_flag_values=re.compile(r'^\d{1,5}$'))
|
20
|
+
port_flag = Flag(flag_name='port', possible_flag_values=re.compile(r'^\d{1,5}$'))
|
21
|
+
short_port_flag = Flag(flag_name='p', flag_prefix='-', possible_flag_values=re.compile(r'^\d{1,5}$'))
|
argenta/router/entity.py
CHANGED
@@ -23,7 +23,7 @@ class Router:
|
|
23
23
|
self._command_entities: list[dict[str, Callable[[], None] | Command]] = []
|
24
24
|
self._ignore_command_register: bool = False
|
25
25
|
|
26
|
-
self._not_valid_flag_handler: Callable[[Flag], None] = lambda flag: print(f"Undefined or incorrect input flag:
|
26
|
+
self._not_valid_flag_handler: Callable[[Flag], None] = lambda flag: print(f"Undefined or incorrect input flag: {flag.get_string_entity()}{(' '+flag.get_value()) if flag.get_value() else ''}")
|
27
27
|
|
28
28
|
|
29
29
|
def command(self, command: Command) -> Callable[[Any], Any]:
|
@@ -116,6 +116,10 @@ class Router:
|
|
116
116
|
return self._title
|
117
117
|
|
118
118
|
|
119
|
+
def set_title(self, title: str):
|
120
|
+
self._title = title
|
121
|
+
|
122
|
+
|
119
123
|
def get_all_commands(self) -> list[str]:
|
120
124
|
all_commands: list[str] = []
|
121
125
|
for command_entity in self._command_entities:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: argenta
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4.1
|
4
4
|
Summary: python library for creating custom shells
|
5
5
|
License: MIT
|
6
6
|
Author: kolo
|
@@ -75,12 +75,11 @@ from argenta.command.flag import FlagsGroup, Flag
|
|
75
75
|
|
76
76
|
router = Router()
|
77
77
|
|
78
|
-
registered_flags = FlagsGroup(
|
78
|
+
registered_flags = FlagsGroup(
|
79
79
|
Flag(flag_name='host',
|
80
80
|
flag_prefix='--',
|
81
81
|
possible_flag_values=re.compile(r'^192.168.\d{1,3}.\d{1,3}$')),
|
82
|
-
Flag('port', '
|
83
|
-
])
|
82
|
+
Flag('port', '--', re.compile(r'^[0-9]{1,4}$')))
|
84
83
|
|
85
84
|
|
86
85
|
@router.command(Command("hello"))
|
@@ -380,8 +379,7 @@ Command(trigger: str,
|
|
380
379
|
```python
|
381
380
|
Flag(flag_name: str,
|
382
381
|
flag_prefix: typing.Literal['-', '--', '---'] = '-',
|
383
|
-
|
384
|
-
possible_flag_values: list[str] | typing.Pattern[str] = False)
|
382
|
+
possible_flag_values: list[str] | typing.Pattern[str] | False = True)
|
385
383
|
```
|
386
384
|
|
387
385
|
---
|
@@ -390,9 +388,10 @@ Flag(flag_name: str,
|
|
390
388
|
- **name : mean**
|
391
389
|
- `flag_name` (`str`): Имя флага
|
392
390
|
- `flag_prefix` (`Literal['-', '--', '---']`): Префикс команды, допустимым значением является от одного до трёх минусов
|
393
|
-
- `
|
394
|
-
|
395
|
-
|
391
|
+
- `possible_flag_values` (`list[str] | Pattern[str] | bool`): Множество допустимых значений флага, может быть задано
|
392
|
+
списком с допустимыми значениями или регулярным выражением (рекомендуется `re.compile(r'example exspression')`), при значении
|
393
|
+
аргумента `False` у введённого флага не может быть значения, иначе будет вызвано исключение и обработано соответствующим
|
394
|
+
еррор-хэндлером
|
396
395
|
|
397
396
|
---
|
398
397
|
|
@@ -425,14 +424,14 @@ Flag(flag_name: str,
|
|
425
424
|
|
426
425
|
### Конструктор
|
427
426
|
```python
|
428
|
-
FlagsGroup(
|
427
|
+
FlagsGroup(*flagы: Flag)
|
429
428
|
```
|
430
429
|
|
431
430
|
---
|
432
431
|
|
433
432
|
**Аргументы:**
|
434
433
|
- **name : mean**
|
435
|
-
-
|
434
|
+
- `*flags` (`Flag`): Неограниченное количество передаваемых флагов
|
436
435
|
|
437
436
|
---
|
438
437
|
|
@@ -1,19 +1,20 @@
|
|
1
1
|
argenta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
argenta/app/__init__.py,sha256=NoKJpO5inI4bEtptNj7BZtNpGQidCNoFSw2-JoK6P98,25
|
3
|
-
argenta/app/entity.py,sha256=
|
3
|
+
argenta/app/entity.py,sha256=9vRk66GQD-3kC--alv21gM_rqyA9ZzKfzXy0jVD6cO0,12506
|
4
4
|
argenta/app/exceptions.py,sha256=ruI_MwJQtBLrnWxJbKlSRE50c5FjnZ9qXJma34kPZhk,1253
|
5
5
|
argenta/command/__init__.py,sha256=yRSj5CtLjxwjKiokUGdSmuBZPOF_qheRyG0NW1pv7vo,27
|
6
|
-
argenta/command/entity.py,sha256=
|
6
|
+
argenta/command/entity.py,sha256=uICQk5zaD_IG52q2IpFTDiGkTK0G6guPR6Eb9Y-3n0E,4454
|
7
7
|
argenta/command/exceptions.py,sha256=ZhJS_ThdmTgGnZqhSfCfkT_VcfkHTiAU7hAgrme6gQY,555
|
8
8
|
argenta/command/flag/__init__.py,sha256=y6rJLdag5qxONg1CzcP7gi6rCeix9UsG1AVANX3fnJs,68
|
9
|
-
argenta/command/flag/defaults.py,sha256=
|
9
|
+
argenta/command/flag/defaults.py,sha256=FjmqepLflYhp2yQcH2bCLi8nip9Bihb5d_HInuEWD4I,1037
|
10
10
|
argenta/command/flag/entity.py,sha256=osMAh-PVP_1MhRhe4Zf1NmJu5NJWAyY6oOKT9mtZnWw,1542
|
11
11
|
argenta/command/flag/flags_group/__init__.py,sha256=f1q3albNnoQYrY56Exb75oh62miTdxD0ALo5aBWW9_g,30
|
12
|
-
argenta/command/flag/flags_group/entity.py,sha256=
|
12
|
+
argenta/command/flag/flags_group/entity.py,sha256=NcyKjC_N-8d4xARkVCLSK8-PoPrKjSlIbR4SHSa7_us,985
|
13
13
|
argenta/router/__init__.py,sha256=vIU2o3JJ7misRm9mUzUQw5HdverdMDfvHNzkWuYFRBY,26
|
14
|
-
argenta/router/
|
14
|
+
argenta/router/defaults.py,sha256=huftOg1HMjrT_R2SHHOL4eJ5uZHspNEYBSg-mCq9xhU,126
|
15
|
+
argenta/router/entity.py,sha256=w4_LO3jVbQPMu8GHjSW6q-_AdQ_IPQkGJHjYaCVXw-Q,5195
|
15
16
|
argenta/router/exceptions.py,sha256=NseEKrhwvG-H5_qdN-hzq83eJ98jku-PzHspz4CG9PM,796
|
16
|
-
argenta-0.
|
17
|
-
argenta-0.
|
18
|
-
argenta-0.
|
19
|
-
argenta-0.
|
17
|
+
argenta-0.4.1.dist-info/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
|
18
|
+
argenta-0.4.1.dist-info/METADATA,sha256=r7hxvBwmXnaa3GDn3x3bvUlIode_EGFW1E2iCB6wkZY,18187
|
19
|
+
argenta-0.4.1.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
20
|
+
argenta-0.4.1.dist-info/RECORD,,
|
File without changes
|