argenta 0.3.7__tar.gz → 0.3.9__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.7 → argenta-0.3.9}/PKG-INFO +5 -4
- {argenta-0.3.7 → argenta-0.3.9}/README.md +4 -3
- {argenta-0.3.7 → argenta-0.3.9}/argenta/app/entity.py +1 -0
- {argenta-0.3.7 → argenta-0.3.9}/argenta/command/entity.py +12 -10
- {argenta-0.3.7 → argenta-0.3.9}/argenta/command/exceptions.py +1 -1
- argenta-0.3.9/argenta/command/flag/defaults.py +18 -0
- {argenta-0.3.7/argenta/command/params → argenta-0.3.9/argenta/command}/flag/entity.py +14 -16
- argenta-0.3.9/argenta/command/flag/flags_group/__init__.py +1 -0
- {argenta-0.3.7/argenta/command/params → argenta-0.3.9/argenta/command}/flag/flags_group/entity.py +2 -2
- {argenta-0.3.7 → argenta-0.3.9}/argenta/router/entity.py +6 -3
- {argenta-0.3.7 → argenta-0.3.9}/argenta/router/exceptions.py +5 -0
- {argenta-0.3.7 → argenta-0.3.9}/pyproject.toml +2 -1
- argenta-0.3.7/argenta/command/params/__init__.py +0 -0
- argenta-0.3.7/argenta/command/params/flag/flags_group/__init__.py +0 -0
- {argenta-0.3.7 → argenta-0.3.9}/LICENSE +0 -0
- {argenta-0.3.7 → argenta-0.3.9}/argenta/__init__.py +0 -0
- {argenta-0.3.7 → argenta-0.3.9}/argenta/app/__init__.py +0 -0
- {argenta-0.3.7 → argenta-0.3.9}/argenta/app/exceptions.py +0 -0
- {argenta-0.3.7 → argenta-0.3.9}/argenta/command/__init__.py +0 -0
- {argenta-0.3.7/argenta/command/params → argenta-0.3.9/argenta/command}/flag/__init__.py +0 -0
- {argenta-0.3.7 → argenta-0.3.9}/argenta/router/__init__.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: argenta
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.9
|
4
4
|
Summary: python library for creating custom shells
|
5
5
|
License: MIT
|
6
6
|
Author: kolo
|
@@ -71,7 +71,7 @@ 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
|
|
@@ -320,6 +320,7 @@ Router(title: str = 'Commands group title:',
|
|
320
320
|
- `TooManyTransferredArgsException` - Слишком много зарегистрированных аргументов у обработчика команды
|
321
321
|
- `RequiredArgumentNotPassedException` - Не зарегистрирован обязательный аргумент у обработчика команды(аргумент, через который будут переданы флаги введённой команды)
|
322
322
|
- `IncorrectNumberOfHandlerArgsException` - У обработчика нестандартного поведения зарегистрировано неверное количество аргументов(в большинстве случаев у него должен быть один аргумент)
|
323
|
+
- `TriggerCannotContainSpacesException` - У регистрируемой команды в триггере содержатся пробелы
|
323
324
|
|
324
325
|
---
|
325
326
|
|
@@ -378,9 +379,9 @@ Command(trigger: str,
|
|
378
379
|
### Конструктор
|
379
380
|
```python
|
380
381
|
Flag(flag_name: str,
|
381
|
-
flag_prefix: Literal['-', '--', '---'] = '-',
|
382
|
+
flag_prefix: typing.Literal['-', '--', '---'] = '-',
|
382
383
|
ignore_flag_value_register: bool = False,
|
383
|
-
possible_flag_values: list[str] | Pattern[str] = False)
|
384
|
+
possible_flag_values: list[str] | typing.Pattern[str] = False)
|
384
385
|
```
|
385
386
|
|
386
387
|
---
|
@@ -56,7 +56,7 @@ 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
|
|
@@ -305,6 +305,7 @@ Router(title: str = 'Commands group title:',
|
|
305
305
|
- `TooManyTransferredArgsException` - Слишком много зарегистрированных аргументов у обработчика команды
|
306
306
|
- `RequiredArgumentNotPassedException` - Не зарегистрирован обязательный аргумент у обработчика команды(аргумент, через который будут переданы флаги введённой команды)
|
307
307
|
- `IncorrectNumberOfHandlerArgsException` - У обработчика нестандартного поведения зарегистрировано неверное количество аргументов(в большинстве случаев у него должен быть один аргумент)
|
308
|
+
- `TriggerCannotContainSpacesException` - У регистрируемой команды в триггере содержатся пробелы
|
308
309
|
|
309
310
|
---
|
310
311
|
|
@@ -363,9 +364,9 @@ Command(trigger: str,
|
|
363
364
|
### Конструктор
|
364
365
|
```python
|
365
366
|
Flag(flag_name: str,
|
366
|
-
flag_prefix: Literal['-', '--', '---'] = '-',
|
367
|
+
flag_prefix: typing.Literal['-', '--', '---'] = '-',
|
367
368
|
ignore_flag_value_register: bool = False,
|
368
|
-
possible_flag_values: list[str] | Pattern[str] = False)
|
369
|
+
possible_flag_values: list[str] | typing.Pattern[str] = False)
|
369
370
|
```
|
370
371
|
|
371
372
|
---
|
@@ -1,16 +1,15 @@
|
|
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
|
+
CommandType = TypeVar('CommandType')
|
9
10
|
|
10
|
-
T = TypeVar('T')
|
11
11
|
|
12
|
-
|
13
|
-
class Command(Generic[T]):
|
12
|
+
class Command(Generic[CommandType]):
|
14
13
|
def __init__(self, trigger: str,
|
15
14
|
description: str = None,
|
16
15
|
flags: Flag | FlagsGroup = None):
|
@@ -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) -> 'Command[
|
59
|
+
def parse_input_command(raw_command: str) -> 'Command[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,18 @@
|
|
1
|
+
from argenta.command.flag import Flag
|
2
|
+
import re
|
3
|
+
|
4
|
+
|
5
|
+
help_flag = Flag(flag_name='help', possible_flag_values=False)
|
6
|
+
short_help_flag = Flag(flag_name='h', flag_prefix='-', possible_flag_values=False)
|
7
|
+
|
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)
|
10
|
+
|
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)
|
13
|
+
|
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}$'))
|
16
|
+
|
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}$'))
|
@@ -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.7/argenta/command/params → argenta-0.3.9/argenta/command}/flag/flags_group/entity.py
RENAMED
@@ -1,8 +1,8 @@
|
|
1
|
-
from argenta.command.
|
1
|
+
from argenta.command.flag.entity 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,13 +2,14 @@ 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,
|
10
10
|
RequiredArgumentNotPassedException,
|
11
|
-
IncorrectNumberOfHandlerArgsException
|
11
|
+
IncorrectNumberOfHandlerArgsException,
|
12
|
+
TriggerCannotContainSpacesException)
|
12
13
|
|
13
14
|
|
14
15
|
class Router:
|
@@ -71,6 +72,8 @@ class Router:
|
|
71
72
|
|
72
73
|
def _validate_command(self, command: Command):
|
73
74
|
command_name: str = command.get_trigger()
|
75
|
+
if command_name.find(' ') != -1:
|
76
|
+
raise TriggerCannotContainSpacesException()
|
74
77
|
if command_name in self.get_all_commands():
|
75
78
|
raise RepeatedCommandException()
|
76
79
|
if self._ignore_command_register:
|
@@ -21,3 +21,8 @@ class RequiredArgumentNotPassedException(Exception):
|
|
21
21
|
class IncorrectNumberOfHandlerArgsException(Exception):
|
22
22
|
def __str__(self):
|
23
23
|
return "Handler has incorrect number of arguments"
|
24
|
+
|
25
|
+
|
26
|
+
class TriggerCannotContainSpacesException(Exception):
|
27
|
+
def __str__(self):
|
28
|
+
return "Command trigger cannot contain spaces"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "argenta"
|
3
|
-
version = "0.3.
|
3
|
+
version = "0.3.9"
|
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
|