argenta 0.3.1__py3-none-any.whl → 0.3.3__py3-none-any.whl
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/app/entity.py +32 -9
- argenta/command/entity.py +70 -10
- argenta/command/exceptions.py +36 -0
- argenta/command/params/flag/entity.py +9 -3
- argenta/command/params/flag/flags_group/entity.py +7 -5
- argenta/router/entity.py +38 -18
- argenta/router/exceptions.py +10 -5
- {argenta-0.3.1.dist-info → argenta-0.3.3.dist-info}/METADATA +1 -1
- argenta-0.3.3.dist-info/RECORD +19 -0
- argenta/command/input_comand/__init__.py +0 -0
- argenta/command/input_comand/entity.py +0 -66
- argenta/command/input_comand/exceptions.py +0 -39
- argenta/command/params/flag/input_flag/__init__.py +0 -0
- argenta/command/params/flag/input_flag/entity.py +0 -11
- argenta-0.3.1.dist-info/RECORD +0 -24
- {argenta-0.3.1.dist-info → argenta-0.3.3.dist-info}/LICENSE +0 -0
- {argenta-0.3.1.dist-info → argenta-0.3.3.dist-info}/WHEEL +0 -0
argenta/app/entity.py
CHANGED
@@ -3,11 +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
|
-
|
6
|
+
from ..command.exceptions import (UnprocessedInputFlagException,
|
7
|
+
InvalidInputFlagsHandlerHasBeenAlreadyCreatedException,
|
8
|
+
IncorrectNumberOfHandlerArgsException,
|
9
|
+
UnknownCommandHandlerHasBeenAlreadyCreatedException,
|
10
|
+
RepeatedInputFlagsException,
|
11
|
+
RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException)
|
11
12
|
from .exceptions import (InvalidRouterInstanceException,
|
12
13
|
InvalidDescriptionMessagePatternException,
|
13
14
|
NoRegisteredRoutersException,
|
@@ -46,6 +47,7 @@ class App:
|
|
46
47
|
|
47
48
|
self._routers: list[Router] = []
|
48
49
|
self._invalid_input_flags_handler: Callable[[str], None] | None = None
|
50
|
+
self._repeated_input_flags_handler: Callable[[str], None] | None = None
|
49
51
|
self._unknown_command_handler: Callable[[Command], None] | None = None
|
50
52
|
self._registered_router_entities: list[dict[str, str | list[dict[str, Callable[[], None] | Command]] | Router]] = []
|
51
53
|
self._app_main_router: Router | None = None
|
@@ -71,8 +73,8 @@ class App:
|
|
71
73
|
raw_command: str = input()
|
72
74
|
|
73
75
|
try:
|
74
|
-
input_command:
|
75
|
-
except
|
76
|
+
input_command: Command = Command.parse_input_command(raw_command=raw_command)
|
77
|
+
except UnprocessedInputFlagException:
|
76
78
|
self.print_func(self.line_separate)
|
77
79
|
if self._invalid_input_flags_handler:
|
78
80
|
self._invalid_input_flags_handler(raw_command)
|
@@ -82,6 +84,16 @@ class App:
|
|
82
84
|
if not self.repeat_command_groups:
|
83
85
|
self.print_func(self.prompt)
|
84
86
|
continue
|
87
|
+
except RepeatedInputFlagsException:
|
88
|
+
self.print_func(self.line_separate)
|
89
|
+
if self._repeated_input_flags_handler:
|
90
|
+
self._repeated_input_flags_handler(raw_command)
|
91
|
+
else:
|
92
|
+
self.print_func(f'Repeated input flags: "{raw_command}"')
|
93
|
+
self.print_func(self.line_separate)
|
94
|
+
if not self.repeat_command_groups:
|
95
|
+
self.print_func(self.prompt)
|
96
|
+
continue
|
85
97
|
|
86
98
|
self._checking_command_for_exit_command(input_command.get_string_entity())
|
87
99
|
self.print_func(self.line_separate)
|
@@ -125,18 +137,29 @@ class App:
|
|
125
137
|
else:
|
126
138
|
args = getfullargspec(handler).args
|
127
139
|
if len(args) != 1:
|
128
|
-
raise
|
140
|
+
raise IncorrectNumberOfHandlerArgsException()
|
129
141
|
else:
|
130
142
|
self._invalid_input_flags_handler = handler
|
131
143
|
|
132
144
|
|
145
|
+
def set_repeated_input_flags_handler(self, handler: Callable[[str], None]) -> None:
|
146
|
+
if self._repeated_input_flags_handler:
|
147
|
+
raise RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException()
|
148
|
+
else:
|
149
|
+
args = getfullargspec(handler).args
|
150
|
+
if len(args) != 1:
|
151
|
+
raise IncorrectNumberOfHandlerArgsException()
|
152
|
+
else:
|
153
|
+
self._repeated_input_flags_handler = handler
|
154
|
+
|
155
|
+
|
133
156
|
def set_unknown_command_handler(self, handler: Callable[[str], None]) -> None:
|
134
157
|
if self._unknown_command_handler:
|
135
158
|
raise UnknownCommandHandlerHasBeenAlreadyCreatedException()
|
136
159
|
else:
|
137
160
|
args = getfullargspec(handler).args
|
138
161
|
if len(args) != 1:
|
139
|
-
raise
|
162
|
+
raise IncorrectNumberOfHandlerArgsException()
|
140
163
|
else:
|
141
164
|
self._unknown_command_handler = handler
|
142
165
|
|
argenta/command/entity.py
CHANGED
@@ -2,11 +2,15 @@ from .params.flag.entity import Flag
|
|
2
2
|
from .params.flag.flags_group.entity import FlagsGroup
|
3
3
|
from .exceptions import (InvalidCommandInstanceException,
|
4
4
|
InvalidDescriptionInstanceException,
|
5
|
-
InvalidFlagsInstanceException)
|
6
|
-
from .params.flag.input_flag.entity import InputFlag
|
5
|
+
InvalidFlagsInstanceException, UnprocessedInputFlagException, RepeatedInputFlagsException)
|
7
6
|
|
7
|
+
from typing import Generic, TypeVar
|
8
8
|
|
9
|
-
|
9
|
+
|
10
|
+
T = TypeVar('T')
|
11
|
+
|
12
|
+
|
13
|
+
class Command(Generic[T]):
|
10
14
|
def __init__(self, command: str,
|
11
15
|
description: str | None = None,
|
12
16
|
flags: Flag | FlagsGroup | None = None):
|
@@ -14,11 +18,13 @@ class Command:
|
|
14
18
|
self._description = description
|
15
19
|
self._flags: FlagsGroup | None = flags if isinstance(flags, FlagsGroup) else FlagsGroup([flags]) if isinstance(flags, Flag) else flags
|
16
20
|
|
17
|
-
self._input_flags:
|
21
|
+
self._input_flags: FlagsGroup | None = None
|
22
|
+
|
18
23
|
|
19
24
|
def get_string_entity(self):
|
20
25
|
return self._command
|
21
26
|
|
27
|
+
|
22
28
|
def get_description(self):
|
23
29
|
if not self._description:
|
24
30
|
description = f'description for "{self._command}" command'
|
@@ -26,22 +32,22 @@ class Command:
|
|
26
32
|
else:
|
27
33
|
return self._description
|
28
34
|
|
29
|
-
|
35
|
+
|
36
|
+
def get_registered_flags(self):
|
30
37
|
return self._flags
|
31
38
|
|
32
|
-
def set_command(self, command: str):
|
33
|
-
self._command = command
|
34
39
|
|
35
40
|
def validate_commands_params(self):
|
36
41
|
if not isinstance(self._command, str):
|
37
42
|
raise InvalidCommandInstanceException(self._command)
|
38
43
|
if not isinstance(self._description, str):
|
39
44
|
raise InvalidDescriptionInstanceException()
|
40
|
-
if not any([(isinstance(self._flags,
|
45
|
+
if not any([(isinstance(self._flags, FlagsGroup)), not self._flags]):
|
41
46
|
raise InvalidFlagsInstanceException
|
42
47
|
|
43
|
-
|
44
|
-
|
48
|
+
|
49
|
+
def validate_input_flag(self, flag: Flag):
|
50
|
+
registered_flags: FlagsGroup | None = self.get_registered_flags()
|
45
51
|
if registered_flags:
|
46
52
|
if isinstance(registered_flags, Flag):
|
47
53
|
if registered_flags.get_string_entity() == flag.get_string_entity():
|
@@ -57,4 +63,58 @@ class Command:
|
|
57
63
|
return False
|
58
64
|
|
59
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
|
+
|
60
120
|
|
argenta/command/exceptions.py
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
from .params.flag.entity import Flag
|
2
|
+
|
3
|
+
|
1
4
|
class InvalidCommandInstanceException(Exception):
|
2
5
|
def __str__(self):
|
3
6
|
return "Invalid Command Instance"
|
@@ -11,3 +14,36 @@ class InvalidDescriptionInstanceException(Exception):
|
|
11
14
|
class InvalidFlagsInstanceException(Exception):
|
12
15
|
def __str__(self):
|
13
16
|
return "Invalid Flags Instance"
|
17
|
+
|
18
|
+
|
19
|
+
class UnprocessedInputFlagException(Exception):
|
20
|
+
def __str__(self):
|
21
|
+
return "Unprocessed Input Flags"
|
22
|
+
|
23
|
+
|
24
|
+
class RepeatedInputFlagsException(Exception):
|
25
|
+
def __init__(self, flag: Flag):
|
26
|
+
self.flag = flag
|
27
|
+
def __str__(self):
|
28
|
+
return ("Repeated Input Flags\n"
|
29
|
+
f"Duplicate flag was detected in the input: '{self.flag.get_string_entity()}'")
|
30
|
+
|
31
|
+
|
32
|
+
class InvalidInputFlagsHandlerHasBeenAlreadyCreatedException(Exception):
|
33
|
+
def __str__(self):
|
34
|
+
return "Invalid Input Flags Handler has already been created"
|
35
|
+
|
36
|
+
|
37
|
+
class RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException(Exception):
|
38
|
+
def __str__(self):
|
39
|
+
return "Repeated Input Flags Handler has already been created"
|
40
|
+
|
41
|
+
|
42
|
+
class UnknownCommandHandlerHasBeenAlreadyCreatedException(Exception):
|
43
|
+
def __str__(self):
|
44
|
+
return "Unknown Command Handler has already been created"
|
45
|
+
|
46
|
+
|
47
|
+
class IncorrectNumberOfHandlerArgsException(Exception):
|
48
|
+
def __str__(self):
|
49
|
+
return "Incorrect Input Flags Handler has incorrect number of arguments"
|
@@ -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):
|
@@ -20,3 +19,6 @@ class FlagsGroup:
|
|
20
19
|
|
21
20
|
def __next__(self):
|
22
21
|
return next(iter(self))
|
22
|
+
|
23
|
+
def __getitem__(self, item):
|
24
|
+
return self._flags[item]
|
argenta/router/entity.py
CHANGED
@@ -1,13 +1,12 @@
|
|
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
|
-
from ..command.input_comand.exceptions import InvalidInputFlagException
|
6
4
|
from ..command.params.flag.flags_group.entity import FlagsGroup
|
7
5
|
from ..router.exceptions import (RepeatedCommandException, RepeatedFlagNameException,
|
8
|
-
CurrentCommandDoesNotProcessFlagsException,
|
9
6
|
TooManyTransferredArgsException,
|
10
|
-
RequiredArgumentNotPassedException
|
7
|
+
RequiredArgumentNotPassedException,
|
8
|
+
NotValidInputFlagHandlerHasBeenAlreadyCreatedException,
|
9
|
+
IncorrectNumberOfHandlerArgsException)
|
11
10
|
|
12
11
|
|
13
12
|
class Router:
|
@@ -21,8 +20,7 @@ class Router:
|
|
21
20
|
self._command_entities: list[dict[str, Callable[[], None] | Command]] = []
|
22
21
|
self._ignore_command_register: bool = False
|
23
22
|
|
24
|
-
self.
|
25
|
-
self._not_valid_flag_handler: Callable[[str], None] | None = None
|
23
|
+
self._not_valid_flag_handler: Callable[[Command], None] | None = None
|
26
24
|
|
27
25
|
|
28
26
|
def command(self, command: Command) -> Callable[[Any], Any]:
|
@@ -39,23 +37,46 @@ class Router:
|
|
39
37
|
|
40
38
|
return command_decorator
|
41
39
|
|
40
|
+
def not_valid_input_flag(self, func):
|
41
|
+
if self._not_valid_flag_handler:
|
42
|
+
raise NotValidInputFlagHandlerHasBeenAlreadyCreatedException()
|
43
|
+
else:
|
44
|
+
processed_args = getfullargspec(func).args
|
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)
|
42
51
|
|
43
|
-
|
52
|
+
return wrapper
|
53
|
+
|
54
|
+
|
55
|
+
def input_command_handler(self, input_command: Command):
|
44
56
|
input_command_name: str = input_command.get_string_entity()
|
57
|
+
input_command_flags: FlagsGroup = input_command.get_input_flags()
|
45
58
|
for command_entity in self._command_entities:
|
46
59
|
if input_command_name.lower() == command_entity['command'].get_string_entity().lower():
|
47
|
-
if command_entity['command'].
|
48
|
-
if
|
49
|
-
for flag in
|
60
|
+
if command_entity['command'].get_registered_flags():
|
61
|
+
if input_command_flags:
|
62
|
+
for flag in input_command_flags:
|
50
63
|
is_valid = command_entity['command'].validate_input_flag(flag)
|
51
64
|
if not is_valid:
|
52
|
-
|
53
|
-
|
65
|
+
if self._not_valid_flag_handler:
|
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()}'")
|
69
|
+
return
|
70
|
+
return command_entity['handler_func'](input_command_flags)
|
54
71
|
else:
|
55
72
|
return command_entity['handler_func'](FlagsGroup(None))
|
56
73
|
else:
|
57
|
-
if
|
58
|
-
|
74
|
+
if input_command_flags:
|
75
|
+
if self._not_valid_flag_handler:
|
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()}'")
|
79
|
+
return
|
59
80
|
else:
|
60
81
|
return command_entity['handler_func']()
|
61
82
|
|
@@ -68,7 +89,7 @@ class Router:
|
|
68
89
|
if command_name.lower() in [x.lower() for x in self.get_all_commands()]:
|
69
90
|
raise RepeatedCommandException()
|
70
91
|
|
71
|
-
flags: FlagsGroup = command.
|
92
|
+
flags: FlagsGroup = command.get_registered_flags()
|
72
93
|
if flags:
|
73
94
|
flags_name: list = [x.get_string_entity().lower() for x in flags]
|
74
95
|
if len(set(flags_name)) < len(flags_name):
|
@@ -77,7 +98,7 @@ class Router:
|
|
77
98
|
|
78
99
|
@staticmethod
|
79
100
|
def _validate_func_args(command: Command, func: Callable):
|
80
|
-
registered_args = command.
|
101
|
+
registered_args = command.get_registered_flags()
|
81
102
|
transferred_args = getfullargspec(func).args
|
82
103
|
if registered_args and transferred_args:
|
83
104
|
if len(transferred_args) != 1:
|
@@ -111,7 +132,6 @@ class Router:
|
|
111
132
|
'ignore_command_register': self._ignore_command_register,
|
112
133
|
'attributes': {
|
113
134
|
'command_entities': self._command_entities,
|
114
|
-
'unknown_command_func': self._unknown_command_handler
|
115
135
|
}
|
116
136
|
|
117
137
|
}
|
@@ -127,6 +147,6 @@ class Router:
|
|
127
147
|
def get_all_flags(self) -> list[FlagsGroup]:
|
128
148
|
all_flags: list[FlagsGroup] = []
|
129
149
|
for command_entity in self._command_entities:
|
130
|
-
all_flags.append(command_entity['command'].
|
150
|
+
all_flags.append(command_entity['command'].get_registered_flags())
|
131
151
|
|
132
152
|
return all_flags
|
argenta/router/exceptions.py
CHANGED
@@ -13,11 +13,6 @@ class RepeatedFlagNameException(Exception):
|
|
13
13
|
return "Repeated flag name in register command"
|
14
14
|
|
15
15
|
|
16
|
-
class CurrentCommandDoesNotProcessFlagsException(Exception):
|
17
|
-
def __str__(self):
|
18
|
-
return "Current command does not process flags"
|
19
|
-
|
20
|
-
|
21
16
|
class TooManyTransferredArgsException(Exception):
|
22
17
|
def __str__(self):
|
23
18
|
return "Too many transferred arguments"
|
@@ -26,3 +21,13 @@ class TooManyTransferredArgsException(Exception):
|
|
26
21
|
class RequiredArgumentNotPassedException(Exception):
|
27
22
|
def __str__(self):
|
28
23
|
return "Required argument not passed"
|
24
|
+
|
25
|
+
|
26
|
+
class NotValidInputFlagHandlerHasBeenAlreadyCreatedException(Exception):
|
27
|
+
def __str__(self):
|
28
|
+
return "Invalid Input Flag Handler has already been created"
|
29
|
+
|
30
|
+
|
31
|
+
class IncorrectNumberOfHandlerArgsException(Exception):
|
32
|
+
def __str__(self):
|
33
|
+
return "Incorrect Input Flags Handler has incorrect number of arguments"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
argenta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
argenta/app/__init__.py,sha256=yOt8-2lholVRUtLPwAXuemh115q1unP1PKLBR_7cd4E,152
|
3
|
+
argenta/app/entity.py,sha256=9E5A4IrAlQ9gibxyeTUcLFTvKEzise8zWV5ZC8AD1AI,11951
|
4
|
+
argenta/app/exceptions.py,sha256=7_p_5NS_paLAU3xGAWufpfkdTxRx07T2zWYzGKdlCMs,1086
|
5
|
+
argenta/command/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
argenta/command/entity.py,sha256=Igd5uaymrLnyJXrDR5bGracTTc51dFmDiEFLByuJYbs,4670
|
7
|
+
argenta/command/exceptions.py,sha256=xxTdm2e7_rhnKQumuJlo-9Srd5y_AdB8iG6Jbl7_ndg,1485
|
8
|
+
argenta/command/params/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
+
argenta/command/params/flag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
+
argenta/command/params/flag/entity.py,sha256=L0ya39MDg4hUIIXJTr19NkiUkIBleW3zjZdaTwmZdOs,1738
|
11
|
+
argenta/command/params/flag/flags_group/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
+
argenta/command/params/flag/flags_group/entity.py,sha256=vicuhXVyf9szr7mt1jokfjBCnaCac_HE8GUM_PJqMMM,591
|
13
|
+
argenta/router/__init__.py,sha256=ZedowNgGR9OphLSg9fXp6-uvjyf23rbq-rEtuHScAIM,87
|
14
|
+
argenta/router/entity.py,sha256=xW33MI_INLe7j9lwmwMzvzgiGqLz5pcw4_TwuOYxJqI,6250
|
15
|
+
argenta/router/exceptions.py,sha256=l9rD_ySeWLYBDPv7R8XYMBWpAE2QOKjYAcZPcTjfUMI,981
|
16
|
+
argenta-0.3.3.dist-info/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
|
17
|
+
argenta-0.3.3.dist-info/METADATA,sha256=3puIx5Gb0liHmi6i6DFkcr8Ck_bWlZMZQsoY2XSoSIc,12638
|
18
|
+
argenta-0.3.3.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
19
|
+
argenta-0.3.3.dist-info/RECORD,,
|
File without changes
|
@@ -1,66 +0,0 @@
|
|
1
|
-
from ..input_comand.exceptions import IncorrectInputFlagException, 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 IncorrectInputFlagException()
|
33
|
-
else:
|
34
|
-
current_flag_name = _
|
35
|
-
else:
|
36
|
-
if not current_flag_name:
|
37
|
-
raise IncorrectInputFlagException()
|
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 IncorrectInputFlagException()
|
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
|
-
|
@@ -1,39 +0,0 @@
|
|
1
|
-
from ..params.flag.input_flag.entity import InputFlag
|
2
|
-
|
3
|
-
|
4
|
-
class InvalidInputFlagException(Exception):
|
5
|
-
def __init__(self, flag: InputFlag):
|
6
|
-
self.flag = flag
|
7
|
-
def __str__(self):
|
8
|
-
return ("Invalid Input Flags\n"
|
9
|
-
f"Unknown or invalid input flag: '{self.flag.get_string_entity()} {self.flag.get_value()}'")
|
10
|
-
|
11
|
-
class IncorrectInputFlagException(Exception):
|
12
|
-
def __str__(self):
|
13
|
-
return "Incorrect Input Flags"
|
14
|
-
|
15
|
-
|
16
|
-
class RepeatedInputFlagsException(Exception):
|
17
|
-
def __init__(self, flag: InputFlag):
|
18
|
-
self.flag = flag
|
19
|
-
def __str__(self):
|
20
|
-
return ("Repeated Input Flags\n"
|
21
|
-
f"Duplicate flag was detected in the input: '{self.flag.get_string_entity()}'")
|
22
|
-
|
23
|
-
|
24
|
-
class InvalidInputFlagsHandlerHasBeenAlreadyCreatedException(Exception):
|
25
|
-
def __str__(self):
|
26
|
-
return "Invalid Input Flags Handler has already been created"
|
27
|
-
|
28
|
-
|
29
|
-
class UnknownCommandHandlerHasBeenAlreadyCreatedException(Exception):
|
30
|
-
def __str__(self):
|
31
|
-
return "Unknown Command Handler has already been created"
|
32
|
-
|
33
|
-
|
34
|
-
class IncorrectNumberArgsHandlerException(Exception):
|
35
|
-
def __str__(self):
|
36
|
-
return "Incorrect Input Flags Handler has incorrect number of arguments"
|
37
|
-
|
38
|
-
|
39
|
-
|
File without changes
|
argenta-0.3.1.dist-info/RECORD
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
argenta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
argenta/app/__init__.py,sha256=yOt8-2lholVRUtLPwAXuemh115q1unP1PKLBR_7cd4E,152
|
3
|
-
argenta/app/entity.py,sha256=wVhagcMloMIh3INmeflAIfMJ_Jgh9K35LB2-FCBwzrs,10840
|
4
|
-
argenta/app/exceptions.py,sha256=7_p_5NS_paLAU3xGAWufpfkdTxRx07T2zWYzGKdlCMs,1086
|
5
|
-
argenta/command/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
argenta/command/entity.py,sha256=9FkU_NbI1WsXrnKA1Ba86xwYoRwLLdk81yI9dj7RsF8,2451
|
7
|
-
argenta/command/exceptions.py,sha256=qTt3G0XaWW5BBQyxNkVWFY0SMGn92VuxvSRs0G37lHI,366
|
8
|
-
argenta/command/input_comand/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
argenta/command/input_comand/entity.py,sha256=YyJPMV8Hy1QSgvgu_w9cjWdiQ2JXG21EbCabns4w_ek,2585
|
10
|
-
argenta/command/input_comand/exceptions.py,sha256=16KtQpv2ZkXPQLu0V28HGoGjfXlxtyJe90pTjDYQbng,1252
|
11
|
-
argenta/command/params/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
-
argenta/command/params/flag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
-
argenta/command/params/flag/entity.py,sha256=gUax6hkuSuarH8yQwFC4QsGql8n1POi19Ww4yEh2c2k,1446
|
14
|
-
argenta/command/params/flag/flags_group/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
|
-
argenta/command/params/flag/flags_group/entity.py,sha256=aFbo5mzevuDxVb8VpaRCUSgUCLn6GK-ODCz5N5650Q8,638
|
16
|
-
argenta/command/params/flag/input_flag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
|
-
argenta/command/params/flag/input_flag/entity.py,sha256=KHoZRE7pRc30LyS6yF_7G7IrA8DrH-gS-Hg_qNstkzU,195
|
18
|
-
argenta/router/__init__.py,sha256=ZedowNgGR9OphLSg9fXp6-uvjyf23rbq-rEtuHScAIM,87
|
19
|
-
argenta/router/entity.py,sha256=NvJZXZl03UTnJOBPsN9KNn4DB7HUL_CQxvrCzICIuWY,5268
|
20
|
-
argenta/router/exceptions.py,sha256=MAgKSmH5hHmIvHAQlIvM1V7Ft_35GA2X3F5e7bR4vcE,789
|
21
|
-
argenta-0.3.1.dist-info/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
|
22
|
-
argenta-0.3.1.dist-info/METADATA,sha256=V0qTkOj2nemtbDlKt8tLm7vi1AroOHwo7RMltFKHwlc,12638
|
23
|
-
argenta-0.3.1.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
24
|
-
argenta-0.3.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|