argenta 0.3.8__tar.gz → 0.4.0__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.8 → argenta-0.4.0}/PKG-INFO +11 -12
- {argenta-0.3.8 → argenta-0.4.0}/README.md +10 -11
- {argenta-0.3.8 → argenta-0.4.0}/argenta/app/entity.py +8 -5
- {argenta-0.3.8 → argenta-0.4.0}/argenta/command/entity.py +13 -11
- {argenta-0.3.8 → argenta-0.4.0}/argenta/command/exceptions.py +1 -1
- argenta-0.4.0/argenta/command/flag/defaults.py +21 -0
- {argenta-0.3.8/argenta/command/params → argenta-0.4.0/argenta/command}/flag/entity.py +14 -16
- argenta-0.4.0/argenta/command/flag/flags_group/__init__.py +1 -0
- {argenta-0.3.8/argenta/command/params → argenta-0.4.0/argenta/command}/flag/flags_group/entity.py +2 -2
- {argenta-0.3.8 → argenta-0.4.0}/argenta/router/entity.py +3 -3
- {argenta-0.3.8 → argenta-0.4.0}/pyproject.toml +2 -1
- argenta-0.3.8/argenta/command/params/__init__.py +0 -0
- argenta-0.3.8/argenta/command/params/flag/flags_group/__init__.py +0 -0
- {argenta-0.3.8 → argenta-0.4.0}/LICENSE +0 -0
- {argenta-0.3.8 → argenta-0.4.0}/argenta/__init__.py +0 -0
- {argenta-0.3.8 → argenta-0.4.0}/argenta/app/__init__.py +0 -0
- {argenta-0.3.8 → argenta-0.4.0}/argenta/app/exceptions.py +0 -0
- {argenta-0.3.8 → argenta-0.4.0}/argenta/command/__init__.py +0 -0
- {argenta-0.3.8/argenta/command/params → argenta-0.4.0/argenta/command}/flag/__init__.py +0 -0
- {argenta-0.3.8 → argenta-0.4.0}/argenta/router/__init__.py +0 -0
- {argenta-0.3.8 → argenta-0.4.0}/argenta/router/exceptions.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: argenta
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4.0
|
4
4
|
Summary: python library for creating custom shells
|
5
5
|
License: MIT
|
6
6
|
Author: kolo
|
@@ -71,16 +71,15 @@ if __name__ == '__main__':
|
|
71
71
|
import re
|
72
72
|
from argenta.router import Router
|
73
73
|
from argenta.command import Command
|
74
|
-
from argenta.command.
|
74
|
+
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
|
|
@@ -56,16 +56,15 @@ if __name__ == '__main__':
|
|
56
56
|
import re
|
57
57
|
from argenta.router import Router
|
58
58
|
from argenta.command import Command
|
59
|
-
from argenta.command.
|
59
|
+
from argenta.command.flag import FlagsGroup, Flag
|
60
60
|
|
61
61
|
router = Router()
|
62
62
|
|
63
|
-
registered_flags = FlagsGroup(
|
63
|
+
registered_flags = FlagsGroup(
|
64
64
|
Flag(flag_name='host',
|
65
65
|
flag_prefix='--',
|
66
66
|
possible_flag_values=re.compile(r'^192.168.\d{1,3}.\d{1,3}$')),
|
67
|
-
Flag('port', '
|
68
|
-
])
|
67
|
+
Flag('port', '--', re.compile(r'^[0-9]{1,4}$')))
|
69
68
|
|
70
69
|
|
71
70
|
@router.command(Command("hello"))
|
@@ -365,8 +364,7 @@ Command(trigger: str,
|
|
365
364
|
```python
|
366
365
|
Flag(flag_name: str,
|
367
366
|
flag_prefix: typing.Literal['-', '--', '---'] = '-',
|
368
|
-
|
369
|
-
possible_flag_values: list[str] | typing.Pattern[str] = False)
|
367
|
+
possible_flag_values: list[str] | typing.Pattern[str] | False = True)
|
370
368
|
```
|
371
369
|
|
372
370
|
---
|
@@ -375,9 +373,10 @@ Flag(flag_name: str,
|
|
375
373
|
- **name : mean**
|
376
374
|
- `flag_name` (`str`): Имя флага
|
377
375
|
- `flag_prefix` (`Literal['-', '--', '---']`): Префикс команды, допустимым значением является от одного до трёх минусов
|
378
|
-
- `
|
379
|
-
|
380
|
-
|
376
|
+
- `possible_flag_values` (`list[str] | Pattern[str] | bool`): Множество допустимых значений флага, может быть задано
|
377
|
+
списком с допустимыми значениями или регулярным выражением (рекомендуется `re.compile(r'example exspression')`), при значении
|
378
|
+
аргумента `False` у введённого флага не может быть значения, иначе будет вызвано исключение и обработано соответствующим
|
379
|
+
еррор-хэндлером
|
381
380
|
|
382
381
|
---
|
383
382
|
|
@@ -410,14 +409,14 @@ Flag(flag_name: str,
|
|
410
409
|
|
411
410
|
### Конструктор
|
412
411
|
```python
|
413
|
-
FlagsGroup(
|
412
|
+
FlagsGroup(*flagы: Flag)
|
414
413
|
```
|
415
414
|
|
416
415
|
---
|
417
416
|
|
418
417
|
**Аргументы:**
|
419
418
|
- **name : mean**
|
420
|
-
-
|
419
|
+
- `*flags` (`Flag`): Неограниченное количество передаваемых флагов
|
421
420
|
|
422
421
|
---
|
423
422
|
|
@@ -50,7 +50,7 @@ class App:
|
|
50
50
|
self._invalid_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Incorrect flag syntax: "{raw_command}"')
|
51
51
|
self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: "{raw_command}"')
|
52
52
|
self._empty_input_command_handler: Callable[[], None] = lambda: print_func(f'Empty input command')
|
53
|
-
self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.
|
53
|
+
self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_trigger()}")
|
54
54
|
|
55
55
|
|
56
56
|
def start_polling(self) -> None:
|
@@ -100,7 +100,9 @@ class App:
|
|
100
100
|
self.print_func(self.prompt)
|
101
101
|
continue
|
102
102
|
|
103
|
-
self.
|
103
|
+
is_exit = self._is_exit_command(input_command.get_trigger())
|
104
|
+
if is_exit:
|
105
|
+
return
|
104
106
|
|
105
107
|
self.print_func(self.line_separate)
|
106
108
|
is_unknown_command: bool = self._check_is_command_unknown(input_command)
|
@@ -212,15 +214,16 @@ class App:
|
|
212
214
|
raise RepeatedCommandInDifferentRoutersException()
|
213
215
|
|
214
216
|
|
215
|
-
def
|
217
|
+
def _is_exit_command(self, command: str):
|
216
218
|
if command.lower() == self.exit_command.lower():
|
217
219
|
if self.ignore_exit_command_register:
|
218
220
|
self.print_func(self.farewell_message)
|
219
|
-
|
221
|
+
return True
|
220
222
|
else:
|
221
223
|
if command == self.exit_command:
|
222
224
|
self.print_func(self.farewell_message)
|
223
|
-
|
225
|
+
return True
|
226
|
+
return False
|
224
227
|
|
225
228
|
|
226
229
|
def _check_is_command_unknown(self, command: Command):
|
@@ -1,23 +1,22 @@
|
|
1
|
-
from .
|
2
|
-
from .
|
1
|
+
from argenta.command.flag.entity import Flag
|
2
|
+
from argenta.command.flag.flags_group import FlagsGroup
|
3
3
|
from .exceptions import (UnprocessedInputFlagException,
|
4
4
|
RepeatedInputFlagsException,
|
5
5
|
EmptyInputCommandException)
|
6
6
|
|
7
|
-
from typing import Generic, TypeVar
|
7
|
+
from typing import Generic, TypeVar, cast, Literal
|
8
8
|
|
9
9
|
|
10
|
-
|
10
|
+
CommandType = TypeVar('CommandType')
|
11
11
|
|
12
12
|
|
13
|
-
class Command(Generic[
|
13
|
+
class Command(Generic[CommandType]):
|
14
14
|
def __init__(self, trigger: str,
|
15
15
|
description: str = None,
|
16
16
|
flags: Flag | FlagsGroup = None):
|
17
17
|
self._trigger = trigger
|
18
18
|
self._description = f'description for "{self._trigger}" command' if not description else description
|
19
|
-
self._registered_flags: FlagsGroup | None = flags if isinstance(flags, FlagsGroup) else FlagsGroup(
|
20
|
-
|
19
|
+
self._registered_flags: FlagsGroup | None = flags if isinstance(flags, FlagsGroup) else FlagsGroup(flags) if isinstance(flags, Flag) else flags
|
21
20
|
self._input_flags: FlagsGroup | None = None
|
22
21
|
|
23
22
|
|
@@ -57,7 +56,7 @@ class Command(Generic[T]):
|
|
57
56
|
return self._input_flags
|
58
57
|
|
59
58
|
@staticmethod
|
60
|
-
def parse_input_command(raw_command: str) ->
|
59
|
+
def parse_input_command(raw_command: str) -> CommandType:
|
61
60
|
if not raw_command:
|
62
61
|
raise EmptyInputCommandException()
|
63
62
|
list_of_tokens = raw_command.split()
|
@@ -67,7 +66,7 @@ class Command(Generic[T]):
|
|
67
66
|
flags: FlagsGroup = FlagsGroup()
|
68
67
|
current_flag_name = None
|
69
68
|
current_flag_value = None
|
70
|
-
for _ in list_of_tokens:
|
69
|
+
for k, _ in enumerate(list_of_tokens):
|
71
70
|
if _.startswith('-'):
|
72
71
|
flag_prefix_last_symbol_index = _.rfind('-')
|
73
72
|
if current_flag_name or len(_) < 2 or len(_[:flag_prefix_last_symbol_index]) > 3:
|
@@ -79,12 +78,15 @@ class Command(Generic[T]):
|
|
79
78
|
raise UnprocessedInputFlagException()
|
80
79
|
else:
|
81
80
|
current_flag_value = _
|
82
|
-
if current_flag_name
|
81
|
+
if current_flag_name:
|
82
|
+
if not len(list_of_tokens) == k+1:
|
83
|
+
if not list_of_tokens[k+1].startswith('-'):
|
84
|
+
continue
|
83
85
|
flag_prefix_last_symbol_index = current_flag_name.rfind('-')
|
84
86
|
flag_prefix = current_flag_name[:flag_prefix_last_symbol_index+1]
|
85
87
|
flag_name = current_flag_name[flag_prefix_last_symbol_index+1:]
|
86
88
|
input_flag = Flag(flag_name=flag_name,
|
87
|
-
flag_prefix=flag_prefix)
|
89
|
+
flag_prefix=cast(Literal['-', '--', '---'], flag_prefix))
|
88
90
|
input_flag.set_value(current_flag_value)
|
89
91
|
|
90
92
|
all_flags = [x.get_string_entity() for x in flags.get_flags()]
|
@@ -0,0 +1,21 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
from argenta.command.flag import Flag
|
3
|
+
import re
|
4
|
+
|
5
|
+
|
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)
|
10
|
+
|
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)
|
13
|
+
|
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)
|
16
|
+
|
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}$'))
|
19
|
+
|
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}$'))
|
@@ -4,12 +4,10 @@ from typing import Literal, Pattern
|
|
4
4
|
class Flag:
|
5
5
|
def __init__(self, flag_name: str,
|
6
6
|
flag_prefix: Literal['-', '--', '---'] = '--',
|
7
|
-
|
8
|
-
possible_flag_values: list[str] | Pattern[str] = False):
|
7
|
+
possible_flag_values: list[str] | Pattern[str] | False = True):
|
9
8
|
self._flag_name = flag_name
|
10
9
|
self._flag_prefix = flag_prefix
|
11
10
|
self.possible_flag_values = possible_flag_values
|
12
|
-
self.ignore_flag_value_register = ignore_flag_value_register
|
13
11
|
|
14
12
|
self._flag_value = None
|
15
13
|
|
@@ -29,23 +27,23 @@ class Flag:
|
|
29
27
|
def set_value(self, value):
|
30
28
|
self._flag_value = value
|
31
29
|
|
32
|
-
def validate_input_flag_value(self, input_flag_value: str):
|
33
|
-
if
|
30
|
+
def validate_input_flag_value(self, input_flag_value: str | None):
|
31
|
+
if self.possible_flag_values is False:
|
32
|
+
if input_flag_value is None:
|
33
|
+
return True
|
34
|
+
else:
|
35
|
+
return False
|
36
|
+
elif isinstance(self.possible_flag_values, Pattern):
|
34
37
|
is_valid = bool(self.possible_flag_values.match(input_flag_value))
|
35
38
|
if bool(is_valid):
|
36
39
|
return True
|
37
40
|
else:
|
38
41
|
return False
|
39
42
|
|
40
|
-
|
41
|
-
if self.
|
42
|
-
|
43
|
-
return True
|
44
|
-
else:
|
45
|
-
return False
|
43
|
+
elif isinstance(self.possible_flag_values, list):
|
44
|
+
if input_flag_value in self.possible_flag_values:
|
45
|
+
return True
|
46
46
|
else:
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
return False
|
51
|
-
return True
|
47
|
+
return False
|
48
|
+
else:
|
49
|
+
return True
|
@@ -0,0 +1 @@
|
|
1
|
+
from .entity import FlagsGroup
|
{argenta-0.3.8/argenta/command/params → argenta-0.4.0/argenta/command}/flag/flags_group/entity.py
RENAMED
@@ -1,8 +1,8 @@
|
|
1
|
-
from argenta.command.
|
1
|
+
from argenta.command.flag import Flag
|
2
2
|
|
3
3
|
|
4
4
|
class FlagsGroup:
|
5
|
-
def __init__(self, flags:
|
5
|
+
def __init__(self, *flags: Flag):
|
6
6
|
self._flags: list[Flag] = [] if not flags else flags
|
7
7
|
|
8
8
|
def get_flags(self) -> list[Flag]:
|
@@ -2,8 +2,8 @@ from typing import Callable, Any
|
|
2
2
|
from inspect import getfullargspec
|
3
3
|
|
4
4
|
from ..command.entity import Command
|
5
|
-
from
|
6
|
-
from
|
5
|
+
from argenta.command.flag.entity import Flag
|
6
|
+
from argenta.command.flag.flags_group import FlagsGroup
|
7
7
|
from ..router.exceptions import (RepeatedCommandException,
|
8
8
|
RepeatedFlagNameException,
|
9
9
|
TooManyTransferredArgsException,
|
@@ -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]:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "argenta"
|
3
|
-
version = "0.
|
3
|
+
version = "0.4.0"
|
4
4
|
description = "python library for creating custom shells"
|
5
5
|
authors = [
|
6
6
|
{name = "kolo", email = "kolo.is.main@gmail.com"}
|
@@ -33,4 +33,5 @@ numpy = "^2.2.2"
|
|
33
33
|
word2number = "^1.1"
|
34
34
|
numexpr = "^2.10.2"
|
35
35
|
requests = "^2.32.3"
|
36
|
+
pyreadline3 = "^3.5.4"
|
36
37
|
|
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
|