mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
v0.4.1
This commit is contained in:
+30
-18
@@ -2,9 +2,10 @@ from typing import Callable
|
|||||||
from inspect import getfullargspec
|
from inspect import getfullargspec
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from ..command.entity import Command
|
from argenta.command import Command
|
||||||
from ..router.entity import Router
|
from argenta.router import Router
|
||||||
from ..command.exceptions import (UnprocessedInputFlagException,
|
from argenta.router.defaults import system_router
|
||||||
|
from argenta.command.exceptions import (UnprocessedInputFlagException,
|
||||||
RepeatedInputFlagsException,
|
RepeatedInputFlagsException,
|
||||||
EmptyInputCommandException)
|
EmptyInputCommandException)
|
||||||
from .exceptions import (InvalidRouterInstanceException,
|
from .exceptions import (InvalidRouterInstanceException,
|
||||||
@@ -53,9 +54,11 @@ class App:
|
|||||||
self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: "{raw_command}"')
|
self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: "{raw_command}"')
|
||||||
self._empty_input_command_handler: Callable[[], None] = lambda: print_func(f'Empty input command')
|
self._empty_input_command_handler: Callable[[], None] = lambda: print_func(f'Empty input command')
|
||||||
self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_trigger()}")
|
self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_trigger()}")
|
||||||
|
self._exit_command_handler: Callable[[], None] = lambda: print_func(self.farewell_message)
|
||||||
|
|
||||||
|
|
||||||
def start_polling(self) -> None:
|
def start_polling(self) -> None:
|
||||||
|
self._setup_system_router()
|
||||||
self._validate_number_of_routers()
|
self._validate_number_of_routers()
|
||||||
self._validate_included_routers()
|
self._validate_included_routers()
|
||||||
self._validate_all_router_commands()
|
self._validate_all_router_commands()
|
||||||
@@ -105,7 +108,7 @@ class App:
|
|||||||
self.print_func(self.prompt)
|
self.print_func(self.prompt)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
is_exit = self._is_exit_command(input_command.get_trigger())
|
is_exit = self._is_exit_command(input_command)
|
||||||
if is_exit:
|
if is_exit:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -178,6 +181,14 @@ class App:
|
|||||||
self._empty_input_command_handler = handler
|
self._empty_input_command_handler = handler
|
||||||
|
|
||||||
|
|
||||||
|
def set_exit_command_handler(self, handler: Callable[[], None]) -> None:
|
||||||
|
args = getfullargspec(handler).args
|
||||||
|
if len(args) != 0:
|
||||||
|
raise IncorrectNumberOfHandlerArgsException()
|
||||||
|
else:
|
||||||
|
self._exit_command_handler = handler
|
||||||
|
|
||||||
|
|
||||||
def add_message_on_startup(self, message: str) -> None:
|
def add_message_on_startup(self, message: str) -> None:
|
||||||
self.messages_on_startup.append(message)
|
self.messages_on_startup.append(message)
|
||||||
|
|
||||||
@@ -223,14 +234,24 @@ class App:
|
|||||||
raise RepeatedCommandInDifferentRoutersException()
|
raise RepeatedCommandInDifferentRoutersException()
|
||||||
|
|
||||||
|
|
||||||
def _is_exit_command(self, command: str):
|
def _setup_system_router(self):
|
||||||
if command.lower() == self.exit_command.lower():
|
system_router.set_title(self.system_points_title)
|
||||||
|
@system_router.command(Command(self.exit_command, self.exit_command_description))
|
||||||
|
def exit_command():
|
||||||
|
self._exit_command_handler()
|
||||||
|
|
||||||
|
if system_router not in [router['entity'] for router in self._registered_router_entities]:
|
||||||
|
self.include_router(system_router)
|
||||||
|
|
||||||
|
|
||||||
|
def _is_exit_command(self, command: Command):
|
||||||
|
if command.get_trigger().lower() == self.exit_command.lower():
|
||||||
if self.ignore_exit_command_register:
|
if self.ignore_exit_command_register:
|
||||||
self.print_func(self.farewell_message)
|
system_router.input_command_handler(command)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
if command == self.exit_command:
|
if command.get_trigger() == self.exit_command:
|
||||||
self.print_func(self.farewell_message)
|
system_router.input_command_handler(command)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -259,12 +280,3 @@ class App:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.print_func(self.command_group_description_separate)
|
self.print_func(self.command_group_description_separate)
|
||||||
|
|
||||||
self.print_func(self.system_points_title)
|
|
||||||
self.print_func(self._description_message_pattern.format(
|
|
||||||
command=self.exit_command,
|
|
||||||
description=self.exit_command_description
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.print_func(self.command_group_description_separate)
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from argenta.router import Router
|
||||||
|
|
||||||
|
|
||||||
|
system_router = Router(title='System points:',
|
||||||
|
name='System')
|
||||||
@@ -116,6 +116,10 @@ class Router:
|
|||||||
return self._title
|
return self._title
|
||||||
|
|
||||||
|
|
||||||
|
def set_title(self, title: str):
|
||||||
|
self._title = title
|
||||||
|
|
||||||
|
|
||||||
def get_all_commands(self) -> list[str]:
|
def get_all_commands(self) -> list[str]:
|
||||||
all_commands: list[str] = []
|
all_commands: list[str] = []
|
||||||
for command_entity in self._command_entities:
|
for command_entity in self._command_entities:
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import re
|
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
from argenta.command import Command
|
from argenta.command import Command
|
||||||
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
|
||||||
from argenta.router import Router
|
from argenta.router import Router
|
||||||
|
from argenta.router.defaults import system_router
|
||||||
from .handlers_implementation.help_command import help_command
|
from .handlers_implementation.help_command import help_command
|
||||||
|
|
||||||
|
|
||||||
@@ -36,3 +36,4 @@ def command_update():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from rich.console import Console
|
|||||||
|
|
||||||
from argenta.app import App
|
from argenta.app import App
|
||||||
|
|
||||||
|
|
||||||
app: App = App(prompt='[italic white bold]What do you want to do(enter number of action)?',
|
app: App = App(prompt='[italic white bold]What do you want to do(enter number of action)?',
|
||||||
line_separate=f'\n{"[bold green]-[/bold green][bold red]-[/bold red]"*25}\n',
|
line_separate=f'\n{"[bold green]-[/bold green][bold red]-[/bold red]"*25}\n',
|
||||||
print_func=Console().print,
|
print_func=Console().print,
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "argenta"
|
name = "argenta"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
description = "python library for creating custom shells"
|
description = "python library for creating custom shells"
|
||||||
authors = [
|
authors = [
|
||||||
{name = "kolo", email = "kolo.is.main@gmail.com"}
|
{name = "kolo", email = "kolo.is.main@gmail.com"}
|
||||||
|
|||||||
Reference in New Issue
Block a user