argenta 0.3.8__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.8 → argenta-0.3.9}/PKG-INFO +2 -2
- {argenta-0.3.8 → argenta-0.3.9}/README.md +1 -1
- {argenta-0.3.8 → argenta-0.3.9}/argenta/app/entity.py +1 -0
- {argenta-0.3.8 → argenta-0.3.9}/argenta/command/entity.py +12 -10
- {argenta-0.3.8 → argenta-0.3.9}/argenta/command/exceptions.py +1 -1
- argenta-0.3.9/argenta/command/flag/defaults.py +18 -0
- {argenta-0.3.8/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.8/argenta/command/params → argenta-0.3.9/argenta/command}/flag/flags_group/entity.py +2 -2
- {argenta-0.3.8 → argenta-0.3.9}/argenta/router/entity.py +2 -2
- {argenta-0.3.8 → argenta-0.3.9}/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.3.9}/LICENSE +0 -0
- {argenta-0.3.8 → argenta-0.3.9}/argenta/__init__.py +0 -0
- {argenta-0.3.8 → argenta-0.3.9}/argenta/app/__init__.py +0 -0
- {argenta-0.3.8 → argenta-0.3.9}/argenta/app/exceptions.py +0 -0
- {argenta-0.3.8 → argenta-0.3.9}/argenta/command/__init__.py +0 -0
- {argenta-0.3.8/argenta/command/params → argenta-0.3.9/argenta/command}/flag/__init__.py +0 -0
- {argenta-0.3.8 → argenta-0.3.9}/argenta/router/__init__.py +0 -0
- {argenta-0.3.8 → argenta-0.3.9}/argenta/router/exceptions.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
|
|
@@ -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.8/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,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,
|
@@ -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
|
File without changes
|