mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
adding new method for App and new system tests
This commit is contained in:
@@ -29,6 +29,7 @@ class App:
|
|||||||
line_separate: str = '',
|
line_separate: str = '',
|
||||||
command_group_description_separate: str = '',
|
command_group_description_separate: str = '',
|
||||||
repeat_command_groups: bool = True,
|
repeat_command_groups: bool = True,
|
||||||
|
messages_on_startup: list[str] = None,
|
||||||
print_func: Callable[[str], None] = print) -> None:
|
print_func: Callable[[str], None] = print) -> None:
|
||||||
self.prompt = prompt
|
self.prompt = prompt
|
||||||
self.print_func = print_func
|
self.print_func = print_func
|
||||||
@@ -43,6 +44,7 @@ class App:
|
|||||||
self.command_group_description_separate = command_group_description_separate
|
self.command_group_description_separate = command_group_description_separate
|
||||||
self.ignore_command_register = ignore_command_register
|
self.ignore_command_register = ignore_command_register
|
||||||
self.repeat_command_groups = repeat_command_groups
|
self.repeat_command_groups = repeat_command_groups
|
||||||
|
self.messages_on_startup = messages_on_startup if messages_on_startup else []
|
||||||
|
|
||||||
self._routers: list[Router] = []
|
self._routers: list[Router] = []
|
||||||
self._description_message_pattern: str = '[{command}] *=*=* {description}'
|
self._description_message_pattern: str = '[{command}] *=*=* {description}'
|
||||||
@@ -60,6 +62,9 @@ class App:
|
|||||||
|
|
||||||
self.print_func(self.initial_message)
|
self.print_func(self.initial_message)
|
||||||
|
|
||||||
|
for message in self.messages_on_startup:
|
||||||
|
self.print_func(message)
|
||||||
|
|
||||||
if not self.repeat_command_groups:
|
if not self.repeat_command_groups:
|
||||||
self._print_command_group_description()
|
self._print_command_group_description()
|
||||||
self.print_func(self.prompt)
|
self.print_func(self.prompt)
|
||||||
@@ -173,6 +178,10 @@ class App:
|
|||||||
self._empty_input_command_handler = handler
|
self._empty_input_command_handler = handler
|
||||||
|
|
||||||
|
|
||||||
|
def add_message_on_startup(self, message: str) -> None:
|
||||||
|
self.messages_on_startup.append(message)
|
||||||
|
|
||||||
|
|
||||||
def include_router(self, router: Router) -> None:
|
def include_router(self, router: Router) -> None:
|
||||||
if not isinstance(router, Router):
|
if not isinstance(router, Router):
|
||||||
raise InvalidRouterInstanceException()
|
raise InvalidRouterInstanceException()
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ def main():
|
|||||||
app.set_initial_message(initial_greeting)
|
app.set_initial_message(initial_greeting)
|
||||||
app.set_farewell_message(goodbye_message)
|
app.set_farewell_message(goodbye_message)
|
||||||
|
|
||||||
|
app.add_message_on_startup('--help for get helping\n\n')
|
||||||
|
|
||||||
app.set_invalid_input_flags_handler(lambda raw_command: print(f"Invalid input flags: {raw_command}"))
|
app.set_invalid_input_flags_handler(lambda raw_command: print(f"Invalid input flags: {raw_command}"))
|
||||||
app.set_unknown_command_handler(lambda command: print(f"Unknown command: {command.get_trigger()}"))
|
app.set_unknown_command_handler(lambda command: print(f"Unknown command: {command.get_trigger()}"))
|
||||||
app.set_repeated_input_flags_handler(lambda raw_command: print(f"Repeated input flags: {raw_command}"))
|
app.set_repeated_input_flags_handler(lambda raw_command: print(f"Repeated input flags: {raw_command}"))
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import re
|
|||||||
from argenta.app import App
|
from argenta.app import App
|
||||||
from argenta.command import Command
|
from argenta.command import Command
|
||||||
from argenta.router import Router
|
from argenta.router import Router
|
||||||
from argenta.command.flag import Flag, FlagsGroup
|
from argenta.command.flag import FlagsGroup
|
||||||
from argenta.command.flag.defaults import DefaultFlags
|
from argenta.command.flag.defaults import DefaultFlags
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user