This commit is contained in:
2025-03-04 00:03:15 +03:00
parent 404758bd91
commit 2c9c8da13c
4 changed files with 66 additions and 38 deletions
+11 -3
View File
@@ -23,7 +23,7 @@ class App:
invalid_input_flags_message: str = 'Invalid input flags',
exit_command: str = 'Q',
exit_command_description: str = 'Exit command',
exit_command_title: str = 'System points:',
system_points_title: str = 'System points:',
ignore_exit_command_register: bool = True,
ignore_command_register: bool = False,
line_separate: str = '',
@@ -34,7 +34,7 @@ class App:
self.print_func = print_func
self.exit_command = exit_command
self.exit_command_description = exit_command_description
self.exit_command_title = exit_command_title
self.system_points_title = system_points_title
self.ignore_exit_command_register = ignore_exit_command_register
self.farewell_message = farewell_message
self.initial_message = initial_message
@@ -163,6 +163,14 @@ class App:
self._unknown_command_handler = handler
def set_empty_command_handler(self, handler: Callable[[str], None]) -> None:
args = getfullargspec(handler).args
if len(args) != 1:
raise IncorrectNumberOfHandlerArgsException()
else:
self._empty_input_command_handler = handler
def include_router(self, router: Router) -> None:
if not isinstance(router, Router):
raise InvalidRouterInstanceException()
@@ -240,7 +248,7 @@ class App:
)
self.print_func(self.command_group_description_separate)
self.print_func(self.exit_command_title)
self.print_func(self.system_points_title)
self.print_func(self._description_message_pattern.format(
command=self.exit_command,
description=self.exit_command_description
+2 -3
View File
@@ -93,9 +93,8 @@ class Command(Generic[T]):
current_flag_value = _
if current_flag_name and current_flag_value:
flag_prefix_last_symbol_index = current_flag_name.rfind('-')
flag_prefix = current_flag_name[:flag_prefix_last_symbol_index]
flag_name = current_flag_name[flag_prefix_last_symbol_index:]
flag_prefix = current_flag_name[:flag_prefix_last_symbol_index+1]
flag_name = current_flag_name[flag_prefix_last_symbol_index+1:]
input_flag = Flag(flag_name=flag_name,
flag_prefix=flag_prefix)
input_flag.set_value(current_flag_value)
+1 -2
View File
@@ -49,7 +49,6 @@ class Router:
def input_command_handler(self, input_command: Command):
input_command_name: str = input_command.get_string_entity()
input_command_flags: FlagsGroup = input_command.get_input_flags()
input_command_flags_dict: dict = input_command_flags.unparse_to_dict()
for command_entity in self._command_entities:
if input_command_name.lower() == command_entity['command'].get_string_entity().lower():
if command_entity['command'].get_registered_flags():
@@ -59,7 +58,7 @@ class Router:
if not is_valid:
self._not_valid_flag_handler(flag)
return
return command_entity['handler_func'](input_command_flags_dict)
return command_entity['handler_func'](input_command_flags.unparse_to_dict())
else:
return command_entity['handler_func']({})
else: