argenta 0.3.2__tar.gz → 0.3.3__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.2 → argenta-0.3.3}/PKG-INFO +1 -1
- {argenta-0.3.2 → argenta-0.3.3}/argenta/app/entity.py +7 -8
- argenta-0.3.3/argenta/command/entity.py +120 -0
- {argenta-0.3.2/argenta/command/input_comand → argenta-0.3.3/argenta/command}/exceptions.py +17 -5
- {argenta-0.3.2 → argenta-0.3.3}/argenta/command/params/flag/entity.py +9 -3
- {argenta-0.3.2 → argenta-0.3.3}/argenta/command/params/flag/flags_group/entity.py +4 -5
- {argenta-0.3.2 → argenta-0.3.3}/argenta/router/entity.py +5 -6
- {argenta-0.3.2 → argenta-0.3.3}/argenta/router/exceptions.py +0 -3
- {argenta-0.3.2 → argenta-0.3.3}/pyproject.toml +1 -1
- argenta-0.3.2/argenta/command/entity.py +0 -60
- argenta-0.3.2/argenta/command/exceptions.py +0 -13
- argenta-0.3.2/argenta/command/input_comand/entity.py +0 -66
- argenta-0.3.2/argenta/command/params/flag/flags_group/__init__.py +0 -0
- argenta-0.3.2/argenta/command/params/flag/input_flag/__init__.py +0 -0
- argenta-0.3.2/argenta/command/params/flag/input_flag/entity.py +0 -11
- {argenta-0.3.2 → argenta-0.3.3}/LICENSE +0 -0
- {argenta-0.3.2 → argenta-0.3.3}/README.md +0 -0
- {argenta-0.3.2 → argenta-0.3.3}/argenta/__init__.py +0 -0
- {argenta-0.3.2 → argenta-0.3.3}/argenta/app/__init__.py +0 -0
- {argenta-0.3.2 → argenta-0.3.3}/argenta/app/exceptions.py +0 -0
- {argenta-0.3.2 → argenta-0.3.3}/argenta/command/__init__.py +0 -0
- {argenta-0.3.2/argenta/command/input_comand → argenta-0.3.3/argenta/command/params}/__init__.py +0 -0
- {argenta-0.3.2/argenta/command/params → argenta-0.3.3/argenta/command/params/flag}/__init__.py +0 -0
- {argenta-0.3.2/argenta/command/params/flag → argenta-0.3.3/argenta/command/params/flag/flags_group}/__init__.py +0 -0
- {argenta-0.3.2 → argenta-0.3.3}/argenta/router/__init__.py +0 -0
@@ -3,13 +3,12 @@ from inspect import getfullargspec
|
|
3
3
|
|
4
4
|
from ..command.entity import Command
|
5
5
|
from ..router.entity import Router
|
6
|
-
from ..command.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException)
|
6
|
+
from ..command.exceptions import (UnprocessedInputFlagException,
|
7
|
+
InvalidInputFlagsHandlerHasBeenAlreadyCreatedException,
|
8
|
+
IncorrectNumberOfHandlerArgsException,
|
9
|
+
UnknownCommandHandlerHasBeenAlreadyCreatedException,
|
10
|
+
RepeatedInputFlagsException,
|
11
|
+
RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException)
|
13
12
|
from .exceptions import (InvalidRouterInstanceException,
|
14
13
|
InvalidDescriptionMessagePatternException,
|
15
14
|
NoRegisteredRoutersException,
|
@@ -74,7 +73,7 @@ class App:
|
|
74
73
|
raw_command: str = input()
|
75
74
|
|
76
75
|
try:
|
77
|
-
input_command:
|
76
|
+
input_command: Command = Command.parse_input_command(raw_command=raw_command)
|
78
77
|
except UnprocessedInputFlagException:
|
79
78
|
self.print_func(self.line_separate)
|
80
79
|
if self._invalid_input_flags_handler:
|
@@ -0,0 +1,120 @@
|
|
1
|
+
from .params.flag.entity import Flag
|
2
|
+
from .params.flag.flags_group.entity import FlagsGroup
|
3
|
+
from .exceptions import (InvalidCommandInstanceException,
|
4
|
+
InvalidDescriptionInstanceException,
|
5
|
+
InvalidFlagsInstanceException, UnprocessedInputFlagException, RepeatedInputFlagsException)
|
6
|
+
|
7
|
+
from typing import Generic, TypeVar
|
8
|
+
|
9
|
+
|
10
|
+
T = TypeVar('T')
|
11
|
+
|
12
|
+
|
13
|
+
class Command(Generic[T]):
|
14
|
+
def __init__(self, command: str,
|
15
|
+
description: str | None = None,
|
16
|
+
flags: Flag | FlagsGroup | None = None):
|
17
|
+
self._command = command
|
18
|
+
self._description = description
|
19
|
+
self._flags: FlagsGroup | None = flags if isinstance(flags, FlagsGroup) else FlagsGroup([flags]) if isinstance(flags, Flag) else flags
|
20
|
+
|
21
|
+
self._input_flags: FlagsGroup | None = None
|
22
|
+
|
23
|
+
|
24
|
+
def get_string_entity(self):
|
25
|
+
return self._command
|
26
|
+
|
27
|
+
|
28
|
+
def get_description(self):
|
29
|
+
if not self._description:
|
30
|
+
description = f'description for "{self._command}" command'
|
31
|
+
return description
|
32
|
+
else:
|
33
|
+
return self._description
|
34
|
+
|
35
|
+
|
36
|
+
def get_registered_flags(self):
|
37
|
+
return self._flags
|
38
|
+
|
39
|
+
|
40
|
+
def validate_commands_params(self):
|
41
|
+
if not isinstance(self._command, str):
|
42
|
+
raise InvalidCommandInstanceException(self._command)
|
43
|
+
if not isinstance(self._description, str):
|
44
|
+
raise InvalidDescriptionInstanceException()
|
45
|
+
if not any([(isinstance(self._flags, FlagsGroup)), not self._flags]):
|
46
|
+
raise InvalidFlagsInstanceException
|
47
|
+
|
48
|
+
|
49
|
+
def validate_input_flag(self, flag: Flag):
|
50
|
+
registered_flags: FlagsGroup | None = self.get_registered_flags()
|
51
|
+
if registered_flags:
|
52
|
+
if isinstance(registered_flags, Flag):
|
53
|
+
if registered_flags.get_string_entity() == flag.get_string_entity():
|
54
|
+
is_valid = registered_flags.validate_input_flag_value(flag.get_value())
|
55
|
+
if is_valid:
|
56
|
+
return True
|
57
|
+
else:
|
58
|
+
for registered_flag in registered_flags:
|
59
|
+
if registered_flag.get_string_entity() == flag.get_string_entity():
|
60
|
+
is_valid = registered_flag.validate_input_flag_value(flag.get_value())
|
61
|
+
if is_valid:
|
62
|
+
return True
|
63
|
+
return False
|
64
|
+
|
65
|
+
|
66
|
+
def set_input_flags(self, input_flags: FlagsGroup):
|
67
|
+
self._input_flags = input_flags
|
68
|
+
|
69
|
+
def get_input_flags(self) -> FlagsGroup:
|
70
|
+
return self._input_flags
|
71
|
+
|
72
|
+
@staticmethod
|
73
|
+
def parse_input_command(raw_command: str) -> 'Command[T]':
|
74
|
+
list_of_tokens = raw_command.split()
|
75
|
+
command = list_of_tokens[0]
|
76
|
+
list_of_tokens.pop(0)
|
77
|
+
|
78
|
+
flags: FlagsGroup = FlagsGroup()
|
79
|
+
current_flag_name = None
|
80
|
+
current_flag_value = None
|
81
|
+
for _ in list_of_tokens:
|
82
|
+
if _.startswith('-'):
|
83
|
+
flag_prefix_last_symbol_index = _.rfind('-')
|
84
|
+
if current_flag_name or len(_) < 2 or len(_[:flag_prefix_last_symbol_index]) > 3:
|
85
|
+
raise UnprocessedInputFlagException()
|
86
|
+
else:
|
87
|
+
current_flag_name = _
|
88
|
+
else:
|
89
|
+
if not current_flag_name:
|
90
|
+
raise UnprocessedInputFlagException()
|
91
|
+
else:
|
92
|
+
current_flag_value = _
|
93
|
+
if current_flag_name and current_flag_value:
|
94
|
+
flag_prefix_last_symbol_index = current_flag_name.rfind('-')
|
95
|
+
flag_prefix = current_flag_name[:flag_prefix_last_symbol_index]
|
96
|
+
flag_name = current_flag_name[flag_prefix_last_symbol_index:]
|
97
|
+
|
98
|
+
input_flag = Flag(flag_name=flag_name,
|
99
|
+
flag_prefix=flag_prefix)
|
100
|
+
input_flag.set_value(current_flag_value)
|
101
|
+
|
102
|
+
all_flags = [x.get_string_entity() for x in flags.get_flags()]
|
103
|
+
if input_flag.get_string_entity() not in all_flags:
|
104
|
+
flags.add_flag(input_flag)
|
105
|
+
else:
|
106
|
+
raise RepeatedInputFlagsException(input_flag)
|
107
|
+
|
108
|
+
current_flag_name = None
|
109
|
+
current_flag_value = None
|
110
|
+
if any([current_flag_name, current_flag_value]):
|
111
|
+
raise UnprocessedInputFlagException()
|
112
|
+
if len(flags.get_flags()) == 0:
|
113
|
+
return Command(command=command)
|
114
|
+
else:
|
115
|
+
input_command = Command(command=command)
|
116
|
+
input_command.set_input_flags(flags)
|
117
|
+
return input_command
|
118
|
+
|
119
|
+
|
120
|
+
|
@@ -1,4 +1,19 @@
|
|
1
|
-
from
|
1
|
+
from .params.flag.entity import Flag
|
2
|
+
|
3
|
+
|
4
|
+
class InvalidCommandInstanceException(Exception):
|
5
|
+
def __str__(self):
|
6
|
+
return "Invalid Command Instance"
|
7
|
+
|
8
|
+
|
9
|
+
class InvalidDescriptionInstanceException(Exception):
|
10
|
+
def __str__(self):
|
11
|
+
return "Invalid Description Instance"
|
12
|
+
|
13
|
+
|
14
|
+
class InvalidFlagsInstanceException(Exception):
|
15
|
+
def __str__(self):
|
16
|
+
return "Invalid Flags Instance"
|
2
17
|
|
3
18
|
|
4
19
|
class UnprocessedInputFlagException(Exception):
|
@@ -7,7 +22,7 @@ class UnprocessedInputFlagException(Exception):
|
|
7
22
|
|
8
23
|
|
9
24
|
class RepeatedInputFlagsException(Exception):
|
10
|
-
def __init__(self, flag:
|
25
|
+
def __init__(self, flag: Flag):
|
11
26
|
self.flag = flag
|
12
27
|
def __str__(self):
|
13
28
|
return ("Repeated Input Flags\n"
|
@@ -32,6 +47,3 @@ class UnknownCommandHandlerHasBeenAlreadyCreatedException(Exception):
|
|
32
47
|
class IncorrectNumberOfHandlerArgsException(Exception):
|
33
48
|
def __str__(self):
|
34
49
|
return "Incorrect Input Flags Handler has incorrect number of arguments"
|
35
|
-
|
36
|
-
|
37
|
-
|
@@ -1,11 +1,11 @@
|
|
1
|
-
from typing import Literal
|
1
|
+
from typing import Literal, Pattern
|
2
2
|
|
3
3
|
|
4
4
|
class Flag:
|
5
5
|
def __init__(self, flag_name: str,
|
6
6
|
flag_prefix: Literal['-', '--', '---'] = '-',
|
7
7
|
ignore_flag_value_register: bool = False,
|
8
|
-
possible_flag_values: list[str] = False):
|
8
|
+
possible_flag_values: list[str] | Pattern[str] = False):
|
9
9
|
self._flag_name = flag_name
|
10
10
|
self._flag_prefix = flag_prefix
|
11
11
|
self.possible_flag_values = possible_flag_values
|
@@ -30,7 +30,13 @@ class Flag:
|
|
30
30
|
self._value = value
|
31
31
|
|
32
32
|
def validate_input_flag_value(self, input_flag_value: str):
|
33
|
-
if self.possible_flag_values:
|
33
|
+
if isinstance(self.possible_flag_values, Pattern):
|
34
|
+
is_valid = bool(self.possible_flag_values.match(input_flag_value))
|
35
|
+
if bool(is_valid):
|
36
|
+
return True
|
37
|
+
else:
|
38
|
+
return False
|
39
|
+
if isinstance(self.possible_flag_values, list):
|
34
40
|
if self.ignore_flag_value_register:
|
35
41
|
if input_flag_value.lower() in [x.lower() for x in self.possible_flag_values]:
|
36
42
|
return True
|
@@ -1,18 +1,17 @@
|
|
1
1
|
from argenta.command.params.flag.entity import Flag
|
2
|
-
from argenta.command.params.flag.input_flag.entity import InputFlag
|
3
2
|
|
4
3
|
|
5
4
|
class FlagsGroup:
|
6
|
-
def __init__(self, flags: list[Flag
|
7
|
-
self._flags: list[Flag
|
5
|
+
def __init__(self, flags: list[Flag] = None):
|
6
|
+
self._flags: list[Flag] = [] if not flags else flags
|
8
7
|
|
9
8
|
def get_flags(self):
|
10
9
|
return self._flags
|
11
10
|
|
12
|
-
def add_flag(self, flag: Flag
|
11
|
+
def add_flag(self, flag: Flag):
|
13
12
|
self._flags.append(flag)
|
14
13
|
|
15
|
-
def add_flags(self, flags: list[Flag
|
14
|
+
def add_flags(self, flags: list[Flag]):
|
16
15
|
self._flags.extend(flags)
|
17
16
|
|
18
17
|
def __iter__(self):
|
@@ -1,7 +1,6 @@
|
|
1
1
|
from typing import Callable, Any
|
2
2
|
from inspect import getfullargspec
|
3
3
|
from ..command.entity import Command
|
4
|
-
from ..command.input_comand.entity import InputCommand
|
5
4
|
from ..command.params.flag.flags_group.entity import FlagsGroup
|
6
5
|
from ..router.exceptions import (RepeatedCommandException, RepeatedFlagNameException,
|
7
6
|
TooManyTransferredArgsException,
|
@@ -53,12 +52,12 @@ class Router:
|
|
53
52
|
return wrapper
|
54
53
|
|
55
54
|
|
56
|
-
def input_command_handler(self, input_command:
|
55
|
+
def input_command_handler(self, input_command: Command):
|
57
56
|
input_command_name: str = input_command.get_string_entity()
|
58
57
|
input_command_flags: FlagsGroup = input_command.get_input_flags()
|
59
58
|
for command_entity in self._command_entities:
|
60
59
|
if input_command_name.lower() == command_entity['command'].get_string_entity().lower():
|
61
|
-
if command_entity['command'].
|
60
|
+
if command_entity['command'].get_registered_flags():
|
62
61
|
if input_command_flags:
|
63
62
|
for flag in input_command_flags:
|
64
63
|
is_valid = command_entity['command'].validate_input_flag(flag)
|
@@ -90,7 +89,7 @@ class Router:
|
|
90
89
|
if command_name.lower() in [x.lower() for x in self.get_all_commands()]:
|
91
90
|
raise RepeatedCommandException()
|
92
91
|
|
93
|
-
flags: FlagsGroup = command.
|
92
|
+
flags: FlagsGroup = command.get_registered_flags()
|
94
93
|
if flags:
|
95
94
|
flags_name: list = [x.get_string_entity().lower() for x in flags]
|
96
95
|
if len(set(flags_name)) < len(flags_name):
|
@@ -99,7 +98,7 @@ class Router:
|
|
99
98
|
|
100
99
|
@staticmethod
|
101
100
|
def _validate_func_args(command: Command, func: Callable):
|
102
|
-
registered_args = command.
|
101
|
+
registered_args = command.get_registered_flags()
|
103
102
|
transferred_args = getfullargspec(func).args
|
104
103
|
if registered_args and transferred_args:
|
105
104
|
if len(transferred_args) != 1:
|
@@ -148,6 +147,6 @@ class Router:
|
|
148
147
|
def get_all_flags(self) -> list[FlagsGroup]:
|
149
148
|
all_flags: list[FlagsGroup] = []
|
150
149
|
for command_entity in self._command_entities:
|
151
|
-
all_flags.append(command_entity['command'].
|
150
|
+
all_flags.append(command_entity['command'].get_registered_flags())
|
152
151
|
|
153
152
|
return all_flags
|
@@ -1,60 +0,0 @@
|
|
1
|
-
from .params.flag.entity import Flag
|
2
|
-
from .params.flag.flags_group.entity import FlagsGroup
|
3
|
-
from .exceptions import (InvalidCommandInstanceException,
|
4
|
-
InvalidDescriptionInstanceException,
|
5
|
-
InvalidFlagsInstanceException)
|
6
|
-
from .params.flag.input_flag.entity import InputFlag
|
7
|
-
|
8
|
-
|
9
|
-
class Command:
|
10
|
-
def __init__(self, command: str,
|
11
|
-
description: str | None = None,
|
12
|
-
flags: Flag | FlagsGroup | None = None):
|
13
|
-
self._command = command
|
14
|
-
self._description = description
|
15
|
-
self._flags: FlagsGroup | None = flags if isinstance(flags, FlagsGroup) else FlagsGroup([flags]) if isinstance(flags, Flag) else flags
|
16
|
-
|
17
|
-
self._input_flags: InputFlag | FlagsGroup | None = None
|
18
|
-
|
19
|
-
def get_string_entity(self):
|
20
|
-
return self._command
|
21
|
-
|
22
|
-
def get_description(self):
|
23
|
-
if not self._description:
|
24
|
-
description = f'description for "{self._command}" command'
|
25
|
-
return description
|
26
|
-
else:
|
27
|
-
return self._description
|
28
|
-
|
29
|
-
def get_flags(self):
|
30
|
-
return self._flags
|
31
|
-
|
32
|
-
def set_command(self, command: str):
|
33
|
-
self._command = command
|
34
|
-
|
35
|
-
def validate_commands_params(self):
|
36
|
-
if not isinstance(self._command, str):
|
37
|
-
raise InvalidCommandInstanceException(self._command)
|
38
|
-
if not isinstance(self._description, str):
|
39
|
-
raise InvalidDescriptionInstanceException()
|
40
|
-
if not any([(isinstance(self._flags, Flag), isinstance(self._flags, FlagsGroup)), not self._flags]):
|
41
|
-
raise InvalidFlagsInstanceException
|
42
|
-
|
43
|
-
def validate_input_flag(self, flag: InputFlag):
|
44
|
-
registered_flags: FlagsGroup | Flag | None = self._flags
|
45
|
-
if registered_flags:
|
46
|
-
if isinstance(registered_flags, Flag):
|
47
|
-
if registered_flags.get_string_entity() == flag.get_string_entity():
|
48
|
-
is_valid = registered_flags.validate_input_flag_value(flag.get_value())
|
49
|
-
if is_valid:
|
50
|
-
return True
|
51
|
-
else:
|
52
|
-
for registered_flag in registered_flags:
|
53
|
-
if registered_flag.get_string_entity() == flag.get_string_entity():
|
54
|
-
is_valid = registered_flag.validate_input_flag_value(flag.get_value())
|
55
|
-
if is_valid:
|
56
|
-
return True
|
57
|
-
return False
|
58
|
-
|
59
|
-
|
60
|
-
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class InvalidCommandInstanceException(Exception):
|
2
|
-
def __str__(self):
|
3
|
-
return "Invalid Command Instance"
|
4
|
-
|
5
|
-
|
6
|
-
class InvalidDescriptionInstanceException(Exception):
|
7
|
-
def __str__(self):
|
8
|
-
return "Invalid Description Instance"
|
9
|
-
|
10
|
-
|
11
|
-
class InvalidFlagsInstanceException(Exception):
|
12
|
-
def __str__(self):
|
13
|
-
return "Invalid Flags Instance"
|
@@ -1,66 +0,0 @@
|
|
1
|
-
from ..input_comand.exceptions import UnprocessedInputFlagException, RepeatedInputFlagsException
|
2
|
-
from ..entity import Command
|
3
|
-
from ..params.flag.flags_group.entity import FlagsGroup
|
4
|
-
from ..params.flag.input_flag.entity import InputFlag
|
5
|
-
|
6
|
-
from typing import Generic, TypeVar
|
7
|
-
|
8
|
-
|
9
|
-
T = TypeVar('T')
|
10
|
-
|
11
|
-
|
12
|
-
class InputCommand(Command, Generic[T]):
|
13
|
-
def set_input_flags(self, input_flags: FlagsGroup):
|
14
|
-
self._input_flags = input_flags
|
15
|
-
|
16
|
-
def get_input_flags(self) -> FlagsGroup:
|
17
|
-
return self._input_flags
|
18
|
-
|
19
|
-
@staticmethod
|
20
|
-
def parse(raw_command: str) -> 'InputCommand[T]':
|
21
|
-
list_of_tokens = raw_command.split()
|
22
|
-
command = list_of_tokens[0]
|
23
|
-
list_of_tokens.pop(0)
|
24
|
-
|
25
|
-
flags: FlagsGroup = FlagsGroup()
|
26
|
-
current_flag_name = None
|
27
|
-
current_flag_value = None
|
28
|
-
for _ in list_of_tokens:
|
29
|
-
if _.startswith('-'):
|
30
|
-
flag_prefix_last_symbol_index = _.rfind('-')
|
31
|
-
if current_flag_name or len(_) < 2 or len(_[:flag_prefix_last_symbol_index]) > 3:
|
32
|
-
raise UnprocessedInputFlagException()
|
33
|
-
else:
|
34
|
-
current_flag_name = _
|
35
|
-
else:
|
36
|
-
if not current_flag_name:
|
37
|
-
raise UnprocessedInputFlagException()
|
38
|
-
else:
|
39
|
-
current_flag_value = _
|
40
|
-
if current_flag_name and current_flag_value:
|
41
|
-
flag_prefix_last_symbol_index = current_flag_name.rfind('-')
|
42
|
-
flag_prefix = current_flag_name[:flag_prefix_last_symbol_index]
|
43
|
-
flag_name = current_flag_name[flag_prefix_last_symbol_index:]
|
44
|
-
|
45
|
-
input_flag = InputFlag(flag_name=flag_name,
|
46
|
-
flag_prefix=flag_prefix)
|
47
|
-
input_flag.set_value(current_flag_value)
|
48
|
-
|
49
|
-
all_flags = [x.get_string_entity() for x in flags.get_flags()]
|
50
|
-
if input_flag.get_string_entity() not in all_flags:
|
51
|
-
flags.add_flag(input_flag)
|
52
|
-
else:
|
53
|
-
raise RepeatedInputFlagsException(input_flag)
|
54
|
-
|
55
|
-
current_flag_name = None
|
56
|
-
current_flag_value = None
|
57
|
-
if any([current_flag_name, current_flag_value]):
|
58
|
-
raise UnprocessedInputFlagException()
|
59
|
-
if len(flags.get_flags()) == 0:
|
60
|
-
return InputCommand(command=command)
|
61
|
-
else:
|
62
|
-
input_command = InputCommand(command=command)
|
63
|
-
input_command.set_input_flags(flags)
|
64
|
-
return input_command
|
65
|
-
|
66
|
-
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{argenta-0.3.2/argenta/command/input_comand → argenta-0.3.3/argenta/command/params}/__init__.py
RENAMED
File without changes
|
{argenta-0.3.2/argenta/command/params → argenta-0.3.3/argenta/command/params/flag}/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|