mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
pre-release v1.0.0
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
.venv
|
.venv
|
||||||
.idea
|
.idea
|
||||||
dist
|
dist
|
||||||
poetry.lock
|
uv.lock
|
||||||
*__pycache__/
|
*__pycache__/
|
||||||
*.hist*
|
*.hist*
|
||||||
build
|
build
|
||||||
|
|||||||
@@ -69,6 +69,7 @@
|
|||||||
- [**RequiredArgumentNotPassedException** Objects](#requiredargumentnotpassedexception-objects)
|
- [**RequiredArgumentNotPassedException** Objects](#requiredargumentnotpassedexception-objects)
|
||||||
- [**IncorrectNumberOfHandlerArgsException** Objects](#incorrectnumberofhandlerargsexception-objects)
|
- [**IncorrectNumberOfHandlerArgsException** Objects](#incorrectnumberofhandlerargsexception-objects)
|
||||||
- [**TriggerContainSpacesException** Objects](#triggercontainspacesexception-objects)
|
- [**TriggerContainSpacesException** Objects](#triggercontainspacesexception-objects)
|
||||||
|
- [**Tests**](#tests)
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
+15
-14
@@ -1,15 +1,21 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "argenta"
|
name = "argenta"
|
||||||
version = "0.5.0"
|
version = "1.0.0-alpha"
|
||||||
description = "Python library for creating TUI"
|
description = "Python library for creating TUI"
|
||||||
authors = [
|
authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }]
|
||||||
{name = "kolo", email = "kolo.is.main@gmail.com"}
|
|
||||||
]
|
|
||||||
license = {text = "MIT"}
|
|
||||||
readme = "README.md"
|
|
||||||
requires-python = ">=3.11, <4.0"
|
requires-python = ">=3.11, <4.0"
|
||||||
dependencies = ["rich (>=14.0.0,<15.0.0)", "art (>=6.4,<7.0)", "pyreadline3 (>=3.5.4,<4.0.0)"]
|
readme = "README.md"
|
||||||
|
license = { text = "MIT" }
|
||||||
|
dependencies = [
|
||||||
|
"rich (>=14.0.0,<15.0.0)",
|
||||||
|
"art (>=6.4,<7.0)",
|
||||||
|
"pyreadline3 (>=3.5.4,<4.0.0)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"pydoc-markdown>=4.8.2,<5",
|
||||||
|
]
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
exclude = [
|
exclude = [
|
||||||
@@ -21,12 +27,7 @@ exclude = [
|
|||||||
"tests"
|
"tests"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
requires = ["hatchling"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
|
||||||
sphinx = "^8.2.3"
|
|
||||||
pydoc-markdown = "^4.8.2"
|
|
||||||
|
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ class App(BaseApp):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if self._is_exit_command(input_command):
|
if self._is_exit_command(input_command):
|
||||||
system_router.input_command_handler(input_command)
|
system_router.finds_appropriate_handler(input_command)
|
||||||
self._autocompleter.exit_setup()
|
self._autocompleter.exit_setup()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -355,7 +355,7 @@ class App(BaseApp):
|
|||||||
|
|
||||||
with redirect_stdout(io.StringIO()) as f:
|
with redirect_stdout(io.StringIO()) as f:
|
||||||
for registered_router in self._registered_routers:
|
for registered_router in self._registered_routers:
|
||||||
registered_router.input_command_handler(input_command)
|
registered_router.finds_appropriate_handler(input_command)
|
||||||
res: str = f.getvalue()
|
res: str = f.getvalue()
|
||||||
self._print_framed_text(res)
|
self._print_framed_text(res)
|
||||||
|
|
||||||
@@ -42,12 +42,25 @@ class Command(BaseCommand):
|
|||||||
self._aliases = aliases if isinstance(aliases, list) else []
|
self._aliases = aliases if isinstance(aliases, list) else []
|
||||||
|
|
||||||
def get_registered_flags(self) -> Flags:
|
def get_registered_flags(self) -> Flags:
|
||||||
|
"""
|
||||||
|
Private. Returns the registered flags
|
||||||
|
:return: the registered flags as Flags
|
||||||
|
"""
|
||||||
return self._registered_flags
|
return self._registered_flags
|
||||||
|
|
||||||
def get_aliases(self) -> list[str] | None:
|
def get_aliases(self) -> list[str] | list:
|
||||||
|
"""
|
||||||
|
Public. Returns the aliases of the command
|
||||||
|
:return: the aliases of the command as list[str] | list
|
||||||
|
"""
|
||||||
return self._aliases
|
return self._aliases
|
||||||
|
|
||||||
def validate_input_flag(self, flag: InputFlag):
|
def validate_input_flag(self, flag: InputFlag) -> bool:
|
||||||
|
"""
|
||||||
|
Private. Validates the input flag
|
||||||
|
:param flag: input flag for validation
|
||||||
|
:return: is input flag valid as bool
|
||||||
|
"""
|
||||||
registered_flags: Flags | None = self.get_registered_flags()
|
registered_flags: Flags | None = self.get_registered_flags()
|
||||||
if registered_flags:
|
if registered_flags:
|
||||||
if isinstance(registered_flags, Flag):
|
if isinstance(registered_flags, Flag):
|
||||||
@@ -64,6 +77,10 @@ class Command(BaseCommand):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def get_description(self) -> str:
|
def get_description(self) -> str:
|
||||||
|
"""
|
||||||
|
Private. Returns the description of the command
|
||||||
|
:return: the description of the command as str
|
||||||
|
"""
|
||||||
return self._description
|
return self._description
|
||||||
|
|
||||||
|
|
||||||
@@ -71,18 +88,38 @@ class Command(BaseCommand):
|
|||||||
class InputCommand(BaseCommand, Generic[InputCommandType]):
|
class InputCommand(BaseCommand, Generic[InputCommandType]):
|
||||||
def __init__(self, trigger: str,
|
def __init__(self, trigger: str,
|
||||||
input_flags: InputFlag | InputFlags = None):
|
input_flags: InputFlag | InputFlags = None):
|
||||||
|
"""
|
||||||
|
Private. The model of the input command, after parsing
|
||||||
|
:param trigger:the trigger of the command
|
||||||
|
:param input_flags: the input flags
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
super().__init__(trigger)
|
super().__init__(trigger)
|
||||||
self._input_flags: InputFlags = input_flags if isinstance(input_flags, InputFlags) else InputFlags(input_flags) if isinstance(input_flags, InputFlag) else InputFlags()
|
self._input_flags: InputFlags = input_flags if isinstance(input_flags, InputFlags) else InputFlags(input_flags) if isinstance(input_flags, InputFlag) else InputFlags()
|
||||||
|
|
||||||
def _set_input_flags(self, input_flags: InputFlags):
|
def _set_input_flags(self, input_flags: InputFlags) -> None:
|
||||||
|
"""
|
||||||
|
Private. Sets the input flags
|
||||||
|
:param input_flags: the input flags to set
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
self._input_flags = input_flags
|
self._input_flags = input_flags
|
||||||
|
|
||||||
def get_input_flags(self) -> InputFlags:
|
def get_input_flags(self) -> InputFlags:
|
||||||
|
"""
|
||||||
|
Private. Returns the input flags
|
||||||
|
:return: the input flags as InputFlags
|
||||||
|
"""
|
||||||
return self._input_flags
|
return self._input_flags
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(raw_command: str) -> InputCommandType:
|
def parse(raw_command: str) -> InputCommandType:
|
||||||
|
"""
|
||||||
|
Private. Parse the raw input command
|
||||||
|
:param raw_command: raw input command
|
||||||
|
:return: model of the input command, after parsing as InputCommand
|
||||||
|
"""
|
||||||
if not raw_command:
|
if not raw_command:
|
||||||
raise EmptyInputCommandException()
|
raise EmptyInputCommandException()
|
||||||
|
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
from typing import Callable
|
from typing import Callable
|
||||||
from inspect import getfullargspec
|
from inspect import getfullargspec
|
||||||
from argenta.command import Command
|
from src.argenta.command import Command
|
||||||
from argenta.command.models import InputCommand
|
from src.argenta.command.models import InputCommand
|
||||||
from argenta.router.command_handler.entity import CommandHandlers, CommandHandler
|
from src.argenta.router.command_handler.entity import CommandHandlers, CommandHandler
|
||||||
from argenta.command.flag.models import Flag, Flags, InputFlags
|
from src.argenta.command.flag.models import Flag, Flags, InputFlags
|
||||||
from argenta.router.exceptions import (RepeatedFlagNameException,
|
from src.argenta.router.exceptions import (RepeatedFlagNameException,
|
||||||
TooManyTransferredArgsException,
|
TooManyTransferredArgsException,
|
||||||
RequiredArgumentNotPassedException,
|
RequiredArgumentNotPassedException,
|
||||||
IncorrectNumberOfHandlerArgsException,
|
IncorrectNumberOfHandlerArgsException,
|
||||||
TriggerContainSpacesException)
|
TriggerContainSpacesException)
|
||||||
|
|
||||||
|
|
||||||
class Router:
|
class Router:
|
||||||
@@ -58,9 +58,9 @@ class Router:
|
|||||||
self._not_valid_flag_handler = func
|
self._not_valid_flag_handler = func
|
||||||
|
|
||||||
|
|
||||||
def input_command_handler(self, input_command: InputCommand) -> None:
|
def finds_appropriate_handler(self, input_command: InputCommand) -> None:
|
||||||
"""
|
"""
|
||||||
Private. One handler for all input commands
|
Private. Finds the appropriate handler for given input command and passes control to it
|
||||||
:param input_command: input command as InputCommand
|
:param input_command: input command as InputCommand
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
@@ -70,15 +70,14 @@ class Router:
|
|||||||
for command_handler in self._command_handlers:
|
for command_handler in self._command_handlers:
|
||||||
handle_command = command_handler.get_handled_command()
|
handle_command = command_handler.get_handled_command()
|
||||||
if input_command_name.lower() == handle_command.get_trigger().lower():
|
if input_command_name.lower() == handle_command.get_trigger().lower():
|
||||||
self._validate_input_command(input_command_flags, command_handler)
|
self.process_input_command(input_command_flags, command_handler)
|
||||||
elif handle_command.get_aliases():
|
if input_command_name.lower() in handle_command.get_aliases():
|
||||||
if input_command_name.lower() in handle_command.get_aliases():
|
self.process_input_command(input_command_flags, command_handler)
|
||||||
self._validate_input_command(input_command_flags, command_handler)
|
|
||||||
|
|
||||||
|
|
||||||
def _validate_input_command(self, input_command_flags: InputFlags, command_handler: CommandHandler) -> None:
|
def process_input_command(self, input_command_flags: InputFlags, command_handler: CommandHandler) -> None:
|
||||||
"""
|
"""
|
||||||
Private. Validates flags of input command
|
Private. Processes input command with the appropriate handler
|
||||||
:param input_command_flags: input command flags as InputFlags
|
:param input_command_flags: input command flags as InputFlags
|
||||||
:param command_handler: command handler for input command as CommandHandler
|
:param command_handler: command handler for input command as CommandHandler
|
||||||
:return: None
|
:return: None
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from argenta.router import Router
|
from src.argenta.router import Router
|
||||||
from argenta.command import Command
|
from src.argenta.command import Command
|
||||||
from argenta.router.exceptions import TriggerContainSpacesException
|
from src.argenta.router import TriggerContainSpacesException
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user