argenta 0.3.4__tar.gz → 0.3.5__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.4 → argenta-0.3.5}/PKG-INFO +1 -1
- {argenta-0.3.4 → argenta-0.3.5}/argenta/app/entity.py +9 -7
- {argenta-0.3.4 → argenta-0.3.5}/argenta/app/exceptions.py +5 -0
- argenta-0.3.5/argenta/command/__init__.py +1 -0
- {argenta-0.3.4 → argenta-0.3.5}/argenta/command/entity.py +6 -10
- {argenta-0.3.4 → argenta-0.3.5}/argenta/command/exceptions.py +0 -5
- argenta-0.3.5/argenta/command/params/flag/__init__.py +2 -0
- {argenta-0.3.4 → argenta-0.3.5}/argenta/command/params/flag/entity.py +1 -2
- {argenta-0.3.4 → argenta-0.3.5}/argenta/router/entity.py +10 -41
- {argenta-0.3.4 → argenta-0.3.5}/pyproject.toml +2 -2
- argenta-0.3.4/argenta/command/params/flag/__init__.py +0 -0
- argenta-0.3.4/argenta/command/params/flag/flags_group/__init__.py +0 -0
- {argenta-0.3.4 → argenta-0.3.5}/LICENSE +0 -0
- {argenta-0.3.4 → argenta-0.3.5}/README.md +0 -0
- {argenta-0.3.4 → argenta-0.3.5}/argenta/__init__.py +0 -0
- {argenta-0.3.4 → argenta-0.3.5}/argenta/app/__init__.py +0 -0
- {argenta-0.3.4/argenta/command → argenta-0.3.5/argenta/command/params}/__init__.py +0 -0
- {argenta-0.3.4/argenta/command/params → argenta-0.3.5/argenta/command/params/flag/flags_group}/__init__.py +0 -0
- {argenta-0.3.4 → argenta-0.3.5}/argenta/command/params/flag/flags_group/entity.py +0 -0
- {argenta-0.3.4 → argenta-0.3.5}/argenta/router/__init__.py +0 -0
- {argenta-0.3.4 → argenta-0.3.5}/argenta/router/exceptions.py +0 -0
@@ -1,17 +1,18 @@
|
|
1
1
|
from typing import Callable
|
2
2
|
from inspect import getfullargspec
|
3
|
+
import re
|
3
4
|
|
4
5
|
from ..command.entity import Command
|
5
6
|
from ..router.entity import Router
|
6
7
|
from ..command.exceptions import (UnprocessedInputFlagException,
|
7
|
-
IncorrectNumberOfHandlerArgsException,
|
8
8
|
RepeatedInputFlagsException,
|
9
9
|
EmptyInputCommandException)
|
10
10
|
from .exceptions import (InvalidRouterInstanceException,
|
11
11
|
InvalidDescriptionMessagePatternException,
|
12
12
|
NoRegisteredRoutersException,
|
13
13
|
NoRegisteredHandlersException,
|
14
|
-
RepeatedCommandInDifferentRoutersException
|
14
|
+
RepeatedCommandInDifferentRoutersException,
|
15
|
+
IncorrectNumberOfHandlerArgsException)
|
15
16
|
|
16
17
|
|
17
18
|
class App:
|
@@ -129,12 +130,13 @@ class App:
|
|
129
130
|
|
130
131
|
|
131
132
|
def set_description_message_pattern(self, pattern: str) -> None:
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
else:
|
133
|
+
first_check = re.match(r'.*{command}.*', pattern)
|
134
|
+
second_check = re.match(r'.*{description}.*', pattern)
|
135
|
+
|
136
|
+
if bool(first_check) and bool(second_check):
|
137
137
|
self._description_message_pattern: str = pattern
|
138
|
+
else:
|
139
|
+
raise InvalidDescriptionMessagePatternException(pattern)
|
138
140
|
|
139
141
|
|
140
142
|
def set_invalid_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
@@ -28,3 +28,8 @@ class NoRegisteredHandlersException(Exception):
|
|
28
28
|
class RepeatedCommandInDifferentRoutersException(Exception):
|
29
29
|
def __str__(self):
|
30
30
|
return "Commands in different handlers cannot be repeated"
|
31
|
+
|
32
|
+
|
33
|
+
class IncorrectNumberOfHandlerArgsException(Exception):
|
34
|
+
def __str__(self):
|
35
|
+
return "Incorrect Input Flags Handler has incorrect number of arguments"
|
@@ -0,0 +1 @@
|
|
1
|
+
from .entity import Command
|
@@ -15,11 +15,11 @@ T = TypeVar('T')
|
|
15
15
|
|
16
16
|
class Command(Generic[T]):
|
17
17
|
def __init__(self, command: str,
|
18
|
-
description: str
|
18
|
+
description: str = None,
|
19
19
|
flags: Flag | FlagsGroup | None = None):
|
20
20
|
self._command = command
|
21
|
-
self._description = description
|
22
|
-
self.
|
21
|
+
self._description = f'description for "{self._command}" command' if not description else description
|
22
|
+
self._registered_flags: FlagsGroup | None = flags if isinstance(flags, FlagsGroup) else FlagsGroup([flags]) if isinstance(flags, Flag) else flags
|
23
23
|
|
24
24
|
self._input_flags: FlagsGroup | None = None
|
25
25
|
|
@@ -29,15 +29,11 @@ class Command(Generic[T]):
|
|
29
29
|
|
30
30
|
|
31
31
|
def get_description(self):
|
32
|
-
|
33
|
-
description = f'description for "{self._command}" command'
|
34
|
-
return description
|
35
|
-
else:
|
36
|
-
return self._description
|
32
|
+
return self._description
|
37
33
|
|
38
34
|
|
39
35
|
def get_registered_flags(self):
|
40
|
-
return self.
|
36
|
+
return self._registered_flags
|
41
37
|
|
42
38
|
|
43
39
|
def validate_commands_params(self):
|
@@ -45,7 +41,7 @@ class Command(Generic[T]):
|
|
45
41
|
raise InvalidCommandInstanceException(self._command)
|
46
42
|
if not isinstance(self._description, str):
|
47
43
|
raise InvalidDescriptionInstanceException()
|
48
|
-
if not any([(isinstance(self.
|
44
|
+
if not any([(isinstance(self._registered_flags, FlagsGroup)), not self._registered_flags]):
|
49
45
|
raise InvalidFlagsInstanceException
|
50
46
|
|
51
47
|
|
@@ -29,11 +29,6 @@ class RepeatedInputFlagsException(Exception):
|
|
29
29
|
f"Duplicate flag was detected in the input: '{self.flag.get_string_entity()}'")
|
30
30
|
|
31
31
|
|
32
|
-
class IncorrectNumberOfHandlerArgsException(Exception):
|
33
|
-
def __str__(self):
|
34
|
-
return "Incorrect Input Flags Handler has incorrect number of arguments"
|
35
|
-
|
36
|
-
|
37
32
|
class EmptyInputCommandException(Exception):
|
38
33
|
def __str__(self):
|
39
34
|
return "Input Command is empty"
|
@@ -1,11 +1,12 @@
|
|
1
1
|
from typing import Callable, Any
|
2
2
|
from inspect import getfullargspec
|
3
|
+
|
3
4
|
from ..command.entity import Command
|
5
|
+
from ..command.params.flag.entity import Flag
|
4
6
|
from ..command.params.flag.flags_group.entity import FlagsGroup
|
5
7
|
from ..router.exceptions import (RepeatedCommandException, RepeatedFlagNameException,
|
6
8
|
TooManyTransferredArgsException,
|
7
9
|
RequiredArgumentNotPassedException,
|
8
|
-
NotValidInputFlagHandlerHasBeenAlreadyCreatedException,
|
9
10
|
IncorrectNumberOfHandlerArgsException)
|
10
11
|
|
11
12
|
|
@@ -20,7 +21,7 @@ class Router:
|
|
20
21
|
self._command_entities: list[dict[str, Callable[[], None] | Command]] = []
|
21
22
|
self._ignore_command_register: bool = False
|
22
23
|
|
23
|
-
self._not_valid_flag_handler: Callable[[
|
24
|
+
self._not_valid_flag_handler: Callable[[Flag], None] = lambda flag: print(f"Undefined or incorrect input flag: '{flag.get_string_entity()} {flag.get_value()}'")
|
24
25
|
|
25
26
|
|
26
27
|
def command(self, command: Command) -> Callable[[Any], Any]:
|
@@ -37,19 +38,12 @@ class Router:
|
|
37
38
|
|
38
39
|
return command_decorator
|
39
40
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
41
|
+
def set_invalid_input_flag_handler(self, func):
|
42
|
+
processed_args = getfullargspec(func).args
|
43
|
+
if len(processed_args) != 1:
|
44
|
+
raise IncorrectNumberOfHandlerArgsException()
|
43
45
|
else:
|
44
|
-
|
45
|
-
if len(processed_args) != 1:
|
46
|
-
raise IncorrectNumberOfHandlerArgsException()
|
47
|
-
else:
|
48
|
-
self._not_valid_flag_handler = func
|
49
|
-
def wrapper(*args, **kwargs):
|
50
|
-
return func(*args, **kwargs)
|
51
|
-
|
52
|
-
return wrapper
|
46
|
+
self._not_valid_flag_handler = func
|
53
47
|
|
54
48
|
|
55
49
|
def input_command_handler(self, input_command: Command):
|
@@ -62,20 +56,14 @@ class Router:
|
|
62
56
|
for flag in input_command_flags:
|
63
57
|
is_valid = command_entity['command'].validate_input_flag(flag)
|
64
58
|
if not is_valid:
|
65
|
-
|
66
|
-
self._not_valid_flag_handler(input_command)
|
67
|
-
else:
|
68
|
-
print(f"Undefined or incorrect input flag: '{flag.get_string_entity()} {flag.get_value()}'")
|
59
|
+
self._not_valid_flag_handler(flag)
|
69
60
|
return
|
70
61
|
return command_entity['handler_func'](input_command_flags)
|
71
62
|
else:
|
72
63
|
return command_entity['handler_func'](FlagsGroup(None))
|
73
64
|
else:
|
74
65
|
if input_command_flags:
|
75
|
-
|
76
|
-
self._not_valid_flag_handler(input_command)
|
77
|
-
else:
|
78
|
-
print(f"Undefined or incorrect input flag: '{input_command_flags[0].get_string_entity()} {input_command_flags[0].get_value()}'")
|
66
|
+
self._not_valid_flag_handler(input_command_flags[0])
|
79
67
|
return
|
80
68
|
else:
|
81
69
|
return command_entity['handler_func']()
|
@@ -125,28 +113,9 @@ class Router:
|
|
125
113
|
return self.title
|
126
114
|
|
127
115
|
|
128
|
-
def get_router_info(self) -> dict:
|
129
|
-
return {
|
130
|
-
'title': self.title,
|
131
|
-
'name': self.name,
|
132
|
-
'ignore_command_register': self._ignore_command_register,
|
133
|
-
'attributes': {
|
134
|
-
'command_entities': self._command_entities,
|
135
|
-
}
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
|
140
116
|
def get_all_commands(self) -> list[str]:
|
141
117
|
all_commands: list[str] = []
|
142
118
|
for command_entity in self._command_entities:
|
143
119
|
all_commands.append(command_entity['command'].get_string_entity())
|
144
120
|
|
145
121
|
return all_commands
|
146
|
-
|
147
|
-
def get_all_flags(self) -> list[FlagsGroup]:
|
148
|
-
all_flags: list[FlagsGroup] = []
|
149
|
-
for command_entity in self._command_entities:
|
150
|
-
all_flags.append(command_entity['command'].get_registered_flags())
|
151
|
-
|
152
|
-
return all_flags
|
@@ -1,9 +1,9 @@
|
|
1
1
|
[project]
|
2
2
|
name = "argenta"
|
3
|
-
version = "0.3.
|
3
|
+
version = "0.3.5"
|
4
4
|
description = "python library for creating custom shells"
|
5
5
|
authors = [
|
6
|
-
{name = "kolo",email = "kolo.is.main@gmail.com"}
|
6
|
+
{name = "kolo", email = "kolo.is.main@gmail.com"}
|
7
7
|
]
|
8
8
|
license = {text = "MIT"}
|
9
9
|
readme = "README.md"
|
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
|