mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
tests
This commit is contained in:
@@ -7,7 +7,8 @@ from typing import Never
|
||||
|
||||
class AutoCompleter:
|
||||
def __init__(
|
||||
self, history_filename: str | None = None, autocomplete_button: str = "tab"
|
||||
self, history_filename: str | None = None,
|
||||
autocomplete_button: str = "tab"
|
||||
) -> None:
|
||||
"""
|
||||
Public. Configures and implements auto-completion of input command
|
||||
@@ -60,12 +61,16 @@ class AutoCompleter:
|
||||
else:
|
||||
for line in all_commands:
|
||||
readline.add_history(line)
|
||||
|
||||
if not self.history_filename:
|
||||
for line in all_commands:
|
||||
readline.add_history(line)
|
||||
|
||||
readline.set_completer(self._complete)
|
||||
readline.set_completer_delims(readline.get_completer_delims().replace(" ", ""))
|
||||
readline.parse_and_bind(f"{self.autocomplete_button}: complete")
|
||||
|
||||
def exit_setup(self, all_commands: list[str]) -> None:
|
||||
def exit_setup(self, all_commands: list[str], ignore_command_register: bool) -> None:
|
||||
"""
|
||||
Private. Exit setup function
|
||||
:return: None
|
||||
@@ -76,10 +81,16 @@ class AutoCompleter:
|
||||
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:
|
||||
if _is_command_exist(line.split()[0], all_commands, ignore_command_register):
|
||||
pretty_history.append(line)
|
||||
with open(self.history_filename, "w") as history_file:
|
||||
_ = history_file.write("\n".join(pretty_history))
|
||||
|
||||
|
||||
def _is_command_exist(command: str, existing_commands: list[str], ignore_command_register: bool) -> bool:
|
||||
if ignore_command_register:
|
||||
return command.lower() in existing_commands
|
||||
return command in existing_commands
|
||||
|
||||
def _get_history_items() -> list[str] | list[Never]:
|
||||
"""
|
||||
|
||||
@@ -465,7 +465,8 @@ class App(BaseApp):
|
||||
if self._is_exit_command(input_command):
|
||||
system_router.finds_appropriate_handler(input_command)
|
||||
self._autocompleter.exit_setup(
|
||||
list(self._current_matching_triggers_with_routers.keys())
|
||||
list(self._current_matching_triggers_with_routers.keys()),
|
||||
self._ignore_command_register
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
@@ -75,10 +75,10 @@ class BooleanArgument(BaseArgument):
|
||||
|
||||
class InputArgument:
|
||||
def __init__(self, name: str,
|
||||
value: str | None,
|
||||
value: str | Literal[True],
|
||||
founder_class: type[BaseArgument]) -> None:
|
||||
self.name: str = name
|
||||
self.value: str | None = value
|
||||
self.value: str | Literal[True] = value
|
||||
self.founder_class: type[BaseArgument] = founder_class
|
||||
|
||||
def __str__(self) -> str:
|
||||
|
||||
@@ -65,7 +65,7 @@ class ArgParser:
|
||||
|
||||
def _parse_args(self) -> None:
|
||||
self.parsed_argspace = ArgSpace.from_namespace(namespace=self._core.parse_args(),
|
||||
processed_args=self.processed_args)
|
||||
processed_args=self.processed_args)
|
||||
|
||||
def _register_args(self, processed_args: list[ValueArgument | BooleanArgument]) -> None:
|
||||
for arg in processed_args:
|
||||
|
||||
Reference in New Issue
Block a user