mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
some fix
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
.venv
|
*venv
|
||||||
.idea
|
.idea
|
||||||
dist
|
dist
|
||||||
uv.lock
|
uv.lock
|
||||||
|
|||||||
+3
-6
@@ -1,3 +1,5 @@
|
|||||||
|
import platform
|
||||||
|
|
||||||
from argenta.response import Response, Status
|
from argenta.response import Response, Status
|
||||||
from argenta.app import App
|
from argenta.app import App
|
||||||
from argenta.app.dividing_line import StaticDividingLine, DynamicDividingLine
|
from argenta.app.dividing_line import StaticDividingLine, DynamicDividingLine
|
||||||
@@ -14,10 +16,5 @@ from argenta.command.models import InputCommand
|
|||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
|
|
||||||
router = Router()
|
print(platform.system())
|
||||||
|
|
||||||
|
|
||||||
@router.command(Command('some'))
|
|
||||||
def handler(res: Response) -> Response:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from argenta.orchestrator.argparser.arguments import BooleanArgument
|
|||||||
|
|
||||||
arg_parser = ArgParser(processed_args=[BooleanArgument('repeat')])
|
arg_parser = ArgParser(processed_args=[BooleanArgument('repeat')])
|
||||||
app: App = App(dividing_line=DynamicDividingLine(),
|
app: App = App(dividing_line=DynamicDividingLine(),
|
||||||
autocompleter=AutoCompleter('./mock/.hist'),
|
autocompleter=AutoCompleter(),
|
||||||
repeat_command_groups=False,)
|
repeat_command_groups=False,)
|
||||||
orchestrator: Orchestrator = Orchestrator(arg_parser)
|
orchestrator: Orchestrator = Orchestrator(arg_parser)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import readline
|
import readline
|
||||||
|
from typing import Never
|
||||||
|
|
||||||
|
|
||||||
class AutoCompleter:
|
class AutoCompleter:
|
||||||
@@ -12,7 +13,6 @@ class AutoCompleter:
|
|||||||
"""
|
"""
|
||||||
self.history_filename = history_filename
|
self.history_filename = history_filename
|
||||||
self.autocomplete_button = autocomplete_button
|
self.autocomplete_button = autocomplete_button
|
||||||
self.matches: list[str] = []
|
|
||||||
|
|
||||||
def _complete(self, text, state) -> str | None:
|
def _complete(self, text, state) -> str | None:
|
||||||
"""
|
"""
|
||||||
@@ -55,18 +55,26 @@ class AutoCompleter:
|
|||||||
readline.set_completer_delims(readline.get_completer_delims().replace(' ', ''))
|
readline.set_completer_delims(readline.get_completer_delims().replace(' ', ''))
|
||||||
readline.parse_and_bind(f'{self.autocomplete_button}: complete')
|
readline.parse_and_bind(f'{self.autocomplete_button}: complete')
|
||||||
|
|
||||||
def exit_setup(self) -> None:
|
def exit_setup(self, all_commands: list[str]) -> None:
|
||||||
"""
|
"""
|
||||||
Private. Exit setup function
|
Private. Exit setup function
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
if self.history_filename:
|
if self.history_filename:
|
||||||
readline.write_history_file(self.history_filename)
|
readline.write_history_file(self.history_filename)
|
||||||
|
with open(self.history_filename, 'r') as history_file:
|
||||||
|
raw_history = history_file.read()
|
||||||
|
pretty_history: list[str] = []
|
||||||
|
for line in set(raw_history.strip().split('\n')):
|
||||||
|
if line.split()[0] in all_commands:
|
||||||
|
pretty_history.append(line)
|
||||||
|
with open(self.history_filename, 'w') as history_file:
|
||||||
|
history_file.write('\n'.join(pretty_history))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_history_items() -> list[str] | list:
|
def get_history_items() -> list[str] | list[Never]:
|
||||||
"""
|
"""
|
||||||
Private. Returns a list of all commands entered by the user
|
Private. Returns a list of all commands entered by the user
|
||||||
:return: all commands entered by the user as list[str]
|
:return: all commands entered by the user as list[str] | list[Never]
|
||||||
"""
|
"""
|
||||||
return [readline.get_history_item(i) for i in range(1, readline.get_current_history_length() + 1)]
|
return [readline.get_history_item(i) for i in range(1, readline.get_current_history_length() + 1)]
|
||||||
|
|||||||
@@ -354,7 +354,10 @@ class App(BaseApp):
|
|||||||
|
|
||||||
if self._is_exit_command(input_command):
|
if self._is_exit_command(input_command):
|
||||||
system_router.finds_appropriate_handler(input_command)
|
system_router.finds_appropriate_handler(input_command)
|
||||||
self._autocompleter.exit_setup()
|
if self._ignore_command_register:
|
||||||
|
self._autocompleter.exit_setup(self._all_registered_triggers_in_lower)
|
||||||
|
else:
|
||||||
|
self._autocompleter.exit_setup(self._all_registered_triggers_in_default_case)
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._is_unknown_command(input_command):
|
if self._is_unknown_command(input_command):
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from argenta.router.exceptions import (RepeatedFlagNameException,
|
|||||||
|
|
||||||
|
|
||||||
class Router:
|
class Router:
|
||||||
def __init__(self, title: str = None):
|
def __init__(self, title: str | None = 'Awesome title'):
|
||||||
"""
|
"""
|
||||||
Public. Directly configures and manages handlers
|
Public. Directly configures and manages handlers
|
||||||
:param title: the title of the router, displayed when displaying the available commands
|
:param title: the title of the router, displayed when displaying the available commands
|
||||||
|
|||||||
Reference in New Issue
Block a user