argenta 0.4.0__tar.gz → 0.4.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: argenta
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: python library for creating custom shells
5
5
  License: MIT
6
6
  Author: kolo
@@ -2,9 +2,10 @@ from typing import Callable
2
2
  from inspect import getfullargspec
3
3
  import re
4
4
 
5
- from ..command.entity import Command
6
- from ..router.entity import Router
7
- from ..command.exceptions import (UnprocessedInputFlagException,
5
+ from argenta.command import Command
6
+ from argenta.router import Router
7
+ from argenta.router.defaults import system_router
8
+ from argenta.command.exceptions import (UnprocessedInputFlagException,
8
9
  RepeatedInputFlagsException,
9
10
  EmptyInputCommandException)
10
11
  from .exceptions import (InvalidRouterInstanceException,
@@ -29,6 +30,7 @@ class App:
29
30
  line_separate: str = '',
30
31
  command_group_description_separate: str = '',
31
32
  repeat_command_groups: bool = True,
33
+ messages_on_startup: list[str] = None,
32
34
  print_func: Callable[[str], None] = print) -> None:
33
35
  self.prompt = prompt
34
36
  self.print_func = print_func
@@ -43,6 +45,7 @@ class App:
43
45
  self.command_group_description_separate = command_group_description_separate
44
46
  self.ignore_command_register = ignore_command_register
45
47
  self.repeat_command_groups = repeat_command_groups
48
+ self.messages_on_startup = messages_on_startup if messages_on_startup else []
46
49
 
47
50
  self._routers: list[Router] = []
48
51
  self._description_message_pattern: str = '[{command}] *=*=* {description}'
@@ -51,15 +54,20 @@ class App:
51
54
  self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: "{raw_command}"')
52
55
  self._empty_input_command_handler: Callable[[], None] = lambda: print_func(f'Empty input command')
53
56
  self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_trigger()}")
57
+ self._exit_command_handler: Callable[[], None] = lambda: print_func(self.farewell_message)
54
58
 
55
59
 
56
60
  def start_polling(self) -> None:
61
+ self._setup_system_router()
57
62
  self._validate_number_of_routers()
58
63
  self._validate_included_routers()
59
64
  self._validate_all_router_commands()
60
65
 
61
66
  self.print_func(self.initial_message)
62
67
 
68
+ for message in self.messages_on_startup:
69
+ self.print_func(message)
70
+
63
71
  if not self.repeat_command_groups:
64
72
  self._print_command_group_description()
65
73
  self.print_func(self.prompt)
@@ -100,7 +108,7 @@ class App:
100
108
  self.print_func(self.prompt)
101
109
  continue
102
110
 
103
- is_exit = self._is_exit_command(input_command.get_trigger())
111
+ is_exit = self._is_exit_command(input_command)
104
112
  if is_exit:
105
113
  return
106
114
 
@@ -173,6 +181,18 @@ class App:
173
181
  self._empty_input_command_handler = handler
174
182
 
175
183
 
184
+ def set_exit_command_handler(self, handler: Callable[[], None]) -> None:
185
+ args = getfullargspec(handler).args
186
+ if len(args) != 0:
187
+ raise IncorrectNumberOfHandlerArgsException()
188
+ else:
189
+ self._exit_command_handler = handler
190
+
191
+
192
+ def add_message_on_startup(self, message: str) -> None:
193
+ self.messages_on_startup.append(message)
194
+
195
+
176
196
  def include_router(self, router: Router) -> None:
177
197
  if not isinstance(router, Router):
178
198
  raise InvalidRouterInstanceException()
@@ -214,14 +234,24 @@ class App:
214
234
  raise RepeatedCommandInDifferentRoutersException()
215
235
 
216
236
 
217
- def _is_exit_command(self, command: str):
218
- if command.lower() == self.exit_command.lower():
237
+ def _setup_system_router(self):
238
+ system_router.set_title(self.system_points_title)
239
+ @system_router.command(Command(self.exit_command, self.exit_command_description))
240
+ def exit_command():
241
+ self._exit_command_handler()
242
+
243
+ if system_router not in [router['entity'] for router in self._registered_router_entities]:
244
+ self.include_router(system_router)
245
+
246
+
247
+ def _is_exit_command(self, command: Command):
248
+ if command.get_trigger().lower() == self.exit_command.lower():
219
249
  if self.ignore_exit_command_register:
220
- self.print_func(self.farewell_message)
250
+ system_router.input_command_handler(command)
221
251
  return True
222
252
  else:
223
- if command == self.exit_command:
224
- self.print_func(self.farewell_message)
253
+ if command.get_trigger() == self.exit_command:
254
+ system_router.input_command_handler(command)
225
255
  return True
226
256
  return False
227
257
 
@@ -250,12 +280,3 @@ class App:
250
280
  )
251
281
  )
252
282
  self.print_func(self.command_group_description_separate)
253
-
254
- self.print_func(self.system_points_title)
255
- self.print_func(self._description_message_pattern.format(
256
- command=self.exit_command,
257
- description=self.exit_command_description
258
- )
259
- )
260
- self.print_func(self.command_group_description_separate)
261
-
@@ -0,0 +1,5 @@
1
+ from argenta.router import Router
2
+
3
+
4
+ system_router = Router(title='System points:',
5
+ name='System')
@@ -116,6 +116,10 @@ class Router:
116
116
  return self._title
117
117
 
118
118
 
119
+ def set_title(self, title: str):
120
+ self._title = title
121
+
122
+
119
123
  def get_all_commands(self) -> list[str]:
120
124
  all_commands: list[str] = []
121
125
  for command_entity in self._command_entities:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "argenta"
3
- version = "0.4.0"
3
+ version = "0.4.1"
4
4
  description = "python library for creating custom shells"
5
5
  authors = [
6
6
  {name = "kolo", email = "kolo.is.main@gmail.com"}
File without changes
File without changes
File without changes
File without changes