argenta 0.3.1__tar.gz → 0.3.2__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.
Files changed (24) hide show
  1. {argenta-0.3.1 → argenta-0.3.2}/PKG-INFO +1 -1
  2. {argenta-0.3.1 → argenta-0.3.2}/argenta/app/entity.py +30 -6
  3. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/input_comand/entity.py +4 -4
  4. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/input_comand/exceptions.py +8 -10
  5. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/params/flag/flags_group/entity.py +3 -0
  6. {argenta-0.3.1 → argenta-0.3.2}/argenta/router/entity.py +33 -12
  7. {argenta-0.3.1 → argenta-0.3.2}/argenta/router/exceptions.py +13 -5
  8. {argenta-0.3.1 → argenta-0.3.2}/pyproject.toml +1 -3
  9. {argenta-0.3.1 → argenta-0.3.2}/LICENSE +0 -0
  10. {argenta-0.3.1 → argenta-0.3.2}/README.md +0 -0
  11. {argenta-0.3.1 → argenta-0.3.2}/argenta/__init__.py +0 -0
  12. {argenta-0.3.1 → argenta-0.3.2}/argenta/app/__init__.py +0 -0
  13. {argenta-0.3.1 → argenta-0.3.2}/argenta/app/exceptions.py +0 -0
  14. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/__init__.py +0 -0
  15. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/entity.py +0 -0
  16. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/exceptions.py +0 -0
  17. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/input_comand/__init__.py +0 -0
  18. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/params/__init__.py +0 -0
  19. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/params/flag/__init__.py +0 -0
  20. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/params/flag/entity.py +0 -0
  21. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/params/flag/flags_group/__init__.py +0 -0
  22. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/params/flag/input_flag/__init__.py +0 -0
  23. {argenta-0.3.1 → argenta-0.3.2}/argenta/command/params/flag/input_flag/entity.py +0 -0
  24. {argenta-0.3.1 → argenta-0.3.2}/argenta/router/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: argenta
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: python library for creating custom shells
5
5
  License: MIT
6
6
  Author: kolo
@@ -4,10 +4,12 @@ from inspect import getfullargspec
4
4
  from ..command.entity import Command
5
5
  from ..router.entity import Router
6
6
  from ..command.input_comand.entity import InputCommand
7
- from ..command.input_comand.exceptions import (IncorrectInputFlagException,
7
+ from ..command.input_comand.exceptions import (UnprocessedInputFlagException,
8
8
  InvalidInputFlagsHandlerHasBeenAlreadyCreatedException,
9
- IncorrectNumberArgsHandlerException,
10
- UnknownCommandHandlerHasBeenAlreadyCreatedException)
9
+ IncorrectNumberOfHandlerArgsException,
10
+ UnknownCommandHandlerHasBeenAlreadyCreatedException,
11
+ RepeatedInputFlagsException,
12
+ RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException)
11
13
  from .exceptions import (InvalidRouterInstanceException,
12
14
  InvalidDescriptionMessagePatternException,
13
15
  NoRegisteredRoutersException,
@@ -46,6 +48,7 @@ class App:
46
48
 
47
49
  self._routers: list[Router] = []
48
50
  self._invalid_input_flags_handler: Callable[[str], None] | None = None
51
+ self._repeated_input_flags_handler: Callable[[str], None] | None = None
49
52
  self._unknown_command_handler: Callable[[Command], None] | None = None
50
53
  self._registered_router_entities: list[dict[str, str | list[dict[str, Callable[[], None] | Command]] | Router]] = []
51
54
  self._app_main_router: Router | None = None
@@ -72,7 +75,7 @@ class App:
72
75
 
73
76
  try:
74
77
  input_command: InputCommand = InputCommand.parse(raw_command=raw_command)
75
- except IncorrectInputFlagException:
78
+ except UnprocessedInputFlagException:
76
79
  self.print_func(self.line_separate)
77
80
  if self._invalid_input_flags_handler:
78
81
  self._invalid_input_flags_handler(raw_command)
@@ -82,6 +85,16 @@ class App:
82
85
  if not self.repeat_command_groups:
83
86
  self.print_func(self.prompt)
84
87
  continue
88
+ except RepeatedInputFlagsException:
89
+ self.print_func(self.line_separate)
90
+ if self._repeated_input_flags_handler:
91
+ self._repeated_input_flags_handler(raw_command)
92
+ else:
93
+ self.print_func(f'Repeated input flags: "{raw_command}"')
94
+ self.print_func(self.line_separate)
95
+ if not self.repeat_command_groups:
96
+ self.print_func(self.prompt)
97
+ continue
85
98
 
86
99
  self._checking_command_for_exit_command(input_command.get_string_entity())
87
100
  self.print_func(self.line_separate)
@@ -125,18 +138,29 @@ class App:
125
138
  else:
126
139
  args = getfullargspec(handler).args
127
140
  if len(args) != 1:
128
- raise IncorrectNumberArgsHandlerException()
141
+ raise IncorrectNumberOfHandlerArgsException()
129
142
  else:
130
143
  self._invalid_input_flags_handler = handler
131
144
 
132
145
 
146
+ def set_repeated_input_flags_handler(self, handler: Callable[[str], None]) -> None:
147
+ if self._repeated_input_flags_handler:
148
+ raise RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException()
149
+ else:
150
+ args = getfullargspec(handler).args
151
+ if len(args) != 1:
152
+ raise IncorrectNumberOfHandlerArgsException()
153
+ else:
154
+ self._repeated_input_flags_handler = handler
155
+
156
+
133
157
  def set_unknown_command_handler(self, handler: Callable[[str], None]) -> None:
134
158
  if self._unknown_command_handler:
135
159
  raise UnknownCommandHandlerHasBeenAlreadyCreatedException()
136
160
  else:
137
161
  args = getfullargspec(handler).args
138
162
  if len(args) != 1:
139
- raise IncorrectNumberArgsHandlerException()
163
+ raise IncorrectNumberOfHandlerArgsException()
140
164
  else:
141
165
  self._unknown_command_handler = handler
142
166
 
@@ -1,4 +1,4 @@
1
- from ..input_comand.exceptions import IncorrectInputFlagException, RepeatedInputFlagsException
1
+ from ..input_comand.exceptions import UnprocessedInputFlagException, RepeatedInputFlagsException
2
2
  from ..entity import Command
3
3
  from ..params.flag.flags_group.entity import FlagsGroup
4
4
  from ..params.flag.input_flag.entity import InputFlag
@@ -29,12 +29,12 @@ class InputCommand(Command, Generic[T]):
29
29
  if _.startswith('-'):
30
30
  flag_prefix_last_symbol_index = _.rfind('-')
31
31
  if current_flag_name or len(_) < 2 or len(_[:flag_prefix_last_symbol_index]) > 3:
32
- raise IncorrectInputFlagException()
32
+ raise UnprocessedInputFlagException()
33
33
  else:
34
34
  current_flag_name = _
35
35
  else:
36
36
  if not current_flag_name:
37
- raise IncorrectInputFlagException()
37
+ raise UnprocessedInputFlagException()
38
38
  else:
39
39
  current_flag_value = _
40
40
  if current_flag_name and current_flag_value:
@@ -55,7 +55,7 @@ class InputCommand(Command, Generic[T]):
55
55
  current_flag_name = None
56
56
  current_flag_value = None
57
57
  if any([current_flag_name, current_flag_value]):
58
- raise IncorrectInputFlagException()
58
+ raise UnprocessedInputFlagException()
59
59
  if len(flags.get_flags()) == 0:
60
60
  return InputCommand(command=command)
61
61
  else:
@@ -1,16 +1,9 @@
1
1
  from ..params.flag.input_flag.entity import InputFlag
2
2
 
3
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):
4
+ class UnprocessedInputFlagException(Exception):
12
5
  def __str__(self):
13
- return "Incorrect Input Flags"
6
+ return "Unprocessed Input Flags"
14
7
 
15
8
 
16
9
  class RepeatedInputFlagsException(Exception):
@@ -26,12 +19,17 @@ class InvalidInputFlagsHandlerHasBeenAlreadyCreatedException(Exception):
26
19
  return "Invalid Input Flags Handler has already been created"
27
20
 
28
21
 
22
+ class RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException(Exception):
23
+ def __str__(self):
24
+ return "Repeated Input Flags Handler has already been created"
25
+
26
+
29
27
  class UnknownCommandHandlerHasBeenAlreadyCreatedException(Exception):
30
28
  def __str__(self):
31
29
  return "Unknown Command Handler has already been created"
32
30
 
33
31
 
34
- class IncorrectNumberArgsHandlerException(Exception):
32
+ class IncorrectNumberOfHandlerArgsException(Exception):
35
33
  def __str__(self):
36
34
  return "Incorrect Input Flags Handler has incorrect number of arguments"
37
35
 
@@ -20,3 +20,6 @@ class FlagsGroup:
20
20
 
21
21
  def __next__(self):
22
22
  return next(iter(self))
23
+
24
+ def __getitem__(self, item):
25
+ return self._flags[item]
@@ -2,12 +2,12 @@ from typing import Callable, Any
2
2
  from inspect import getfullargspec
3
3
  from ..command.entity import Command
4
4
  from ..command.input_comand.entity import InputCommand
5
- from ..command.input_comand.exceptions import InvalidInputFlagException
6
5
  from ..command.params.flag.flags_group.entity import FlagsGroup
7
6
  from ..router.exceptions import (RepeatedCommandException, RepeatedFlagNameException,
8
- CurrentCommandDoesNotProcessFlagsException,
9
7
  TooManyTransferredArgsException,
10
- RequiredArgumentNotPassedException)
8
+ RequiredArgumentNotPassedException,
9
+ NotValidInputFlagHandlerHasBeenAlreadyCreatedException,
10
+ IncorrectNumberOfHandlerArgsException)
11
11
 
12
12
 
13
13
  class Router:
@@ -21,8 +21,7 @@ class Router:
21
21
  self._command_entities: list[dict[str, Callable[[], None] | Command]] = []
22
22
  self._ignore_command_register: bool = False
23
23
 
24
- self._unknown_command_handler: Callable[[str], None] | None = None
25
- self._not_valid_flag_handler: Callable[[str], None] | None = None
24
+ self._not_valid_flag_handler: Callable[[Command], None] | None = None
26
25
 
27
26
 
28
27
  def command(self, command: Command) -> Callable[[Any], Any]:
@@ -39,23 +38,46 @@ class Router:
39
38
 
40
39
  return command_decorator
41
40
 
41
+ def not_valid_input_flag(self, func):
42
+ if self._not_valid_flag_handler:
43
+ raise NotValidInputFlagHandlerHasBeenAlreadyCreatedException()
44
+ else:
45
+ processed_args = getfullargspec(func).args
46
+ if len(processed_args) != 1:
47
+ raise IncorrectNumberOfHandlerArgsException()
48
+ else:
49
+ self._not_valid_flag_handler = func
50
+ def wrapper(*args, **kwargs):
51
+ return func(*args, **kwargs)
52
+
53
+ return wrapper
54
+
42
55
 
43
56
  def input_command_handler(self, input_command: InputCommand):
44
57
  input_command_name: str = input_command.get_string_entity()
58
+ input_command_flags: FlagsGroup = input_command.get_input_flags()
45
59
  for command_entity in self._command_entities:
46
60
  if input_command_name.lower() == command_entity['command'].get_string_entity().lower():
47
61
  if command_entity['command'].get_flags():
48
- if input_command.get_input_flags():
49
- for flag in input_command.get_input_flags():
62
+ if input_command_flags:
63
+ for flag in input_command_flags:
50
64
  is_valid = command_entity['command'].validate_input_flag(flag)
51
65
  if not is_valid:
52
- raise InvalidInputFlagException(flag)
53
- return command_entity['handler_func'](input_command.get_input_flags())
66
+ if self._not_valid_flag_handler:
67
+ self._not_valid_flag_handler(input_command)
68
+ else:
69
+ print(f"Undefined or incorrect input flag: '{flag.get_string_entity()} {flag.get_value()}'")
70
+ return
71
+ return command_entity['handler_func'](input_command_flags)
54
72
  else:
55
73
  return command_entity['handler_func'](FlagsGroup(None))
56
74
  else:
57
- if input_command.get_input_flags():
58
- raise CurrentCommandDoesNotProcessFlagsException()
75
+ if input_command_flags:
76
+ if self._not_valid_flag_handler:
77
+ self._not_valid_flag_handler(input_command)
78
+ else:
79
+ print(f"Undefined or incorrect input flag: '{input_command_flags[0].get_string_entity()} {input_command_flags[0].get_value()}'")
80
+ return
59
81
  else:
60
82
  return command_entity['handler_func']()
61
83
 
@@ -111,7 +133,6 @@ class Router:
111
133
  'ignore_command_register': self._ignore_command_register,
112
134
  'attributes': {
113
135
  'command_entities': self._command_entities,
114
- 'unknown_command_func': self._unknown_command_handler
115
136
  }
116
137
 
117
138
  }
@@ -1,3 +1,6 @@
1
+ from ..command.params.flag.input_flag.entity import InputFlag
2
+
3
+
1
4
  class InvalidDescriptionInstanceException(Exception):
2
5
  def __str__(self):
3
6
  return "Invalid Description Instance"
@@ -13,11 +16,6 @@ class RepeatedFlagNameException(Exception):
13
16
  return "Repeated flag name in register command"
14
17
 
15
18
 
16
- class CurrentCommandDoesNotProcessFlagsException(Exception):
17
- def __str__(self):
18
- return "Current command does not process flags"
19
-
20
-
21
19
  class TooManyTransferredArgsException(Exception):
22
20
  def __str__(self):
23
21
  return "Too many transferred arguments"
@@ -26,3 +24,13 @@ class TooManyTransferredArgsException(Exception):
26
24
  class RequiredArgumentNotPassedException(Exception):
27
25
  def __str__(self):
28
26
  return "Required argument not passed"
27
+
28
+
29
+ class NotValidInputFlagHandlerHasBeenAlreadyCreatedException(Exception):
30
+ def __str__(self):
31
+ return "Invalid Input Flag Handler has already been created"
32
+
33
+
34
+ class IncorrectNumberOfHandlerArgsException(Exception):
35
+ def __str__(self):
36
+ return "Incorrect Input Flags Handler has incorrect number of arguments"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "argenta"
3
- version = "0.3.1"
3
+ version = "0.3.2"
4
4
  description = "python library for creating custom shells"
5
5
  authors = [
6
6
  {name = "kolo",email = "kolo.is.main@gmail.com"}
@@ -33,6 +33,4 @@ numpy = "^2.2.2"
33
33
  word2number = "^1.1"
34
34
  numexpr = "^2.10.2"
35
35
  requests = "^2.32.3"
36
- tqdm = "^4.67.1"
37
- setuptools = "^75.8.0"
38
36
 
File without changes
File without changes
File without changes
File without changes