style: rename input functions
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -25,10 +25,10 @@ from kiauh.modules.klipper.klipper_utils import (
|
||||
)
|
||||
from kiauh.utils.constants import CURRENT_USER, KLIPPER_DIR, KLIPPER_ENV_DIR
|
||||
from kiauh.utils.input_utils import (
|
||||
get_user_confirm,
|
||||
get_user_number_input,
|
||||
get_user_string_input,
|
||||
get_user_selection_input,
|
||||
get_confirm,
|
||||
get_number_input,
|
||||
get_string_input,
|
||||
get_selection_input,
|
||||
)
|
||||
from kiauh.utils.logger import Logger
|
||||
from kiauh.utils.system_utils import (
|
||||
@@ -83,7 +83,7 @@ def handle_existing_instances(instance_manager: InstanceManager) -> bool:
|
||||
|
||||
if instance_count > 0:
|
||||
print_instance_overview(instance_list)
|
||||
if not get_user_confirm("Add new instances?"):
|
||||
if not get_confirm("Add new instances?"):
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -92,7 +92,7 @@ def handle_existing_instances(instance_manager: InstanceManager) -> bool:
|
||||
def install_klipper(instance_manager: InstanceManager) -> None:
|
||||
instance_list = instance_manager.get_instances()
|
||||
if_adding = " additional" if len(instance_list) > 0 else ""
|
||||
install_count = get_user_number_input(
|
||||
install_count = get_number_input(
|
||||
f"Number of{if_adding} Klipper instances to set up", 1, default=1
|
||||
)
|
||||
|
||||
@@ -157,7 +157,7 @@ def set_instance_names(instance_list, install_count: int) -> List[Union[str, Non
|
||||
# or convert single instance install to multi instance install
|
||||
or (instance_count == 1 and install_count >= 1)
|
||||
):
|
||||
if get_user_confirm("Assign custom names?", False):
|
||||
if get_confirm("Assign custom names?", False):
|
||||
return assign_custom_names(instance_count, install_count, None)
|
||||
else:
|
||||
_range = range(1, install_count + 1)
|
||||
@@ -195,7 +195,7 @@ def assign_custom_names(
|
||||
|
||||
for i in range(instance_count + install_count):
|
||||
question = f"Enter name for instance {i + 1}"
|
||||
name = get_user_string_input(question, exclude=exclude)
|
||||
name = get_string_input(question, exclude=exclude)
|
||||
instance_names.append(name)
|
||||
exclude.append(name)
|
||||
|
||||
@@ -227,7 +227,7 @@ def remove_multi_instance(instance_manager: InstanceManager) -> None:
|
||||
options = [str(i) for i in range(len(instance_list))]
|
||||
options.extend(["a", "A", "b", "B"])
|
||||
|
||||
selection = get_user_selection_input("Select Klipper instance to remove", options)
|
||||
selection = get_selection_input("Select Klipper instance to remove", options)
|
||||
print(selection)
|
||||
|
||||
if selection == "b".lower():
|
||||
@@ -265,7 +265,7 @@ def check_user_groups():
|
||||
return
|
||||
|
||||
print_missing_usergroup_dialog(missing_groups)
|
||||
if not get_user_confirm(f"Add user '{CURRENT_USER}' to group(s) now?"):
|
||||
if not get_confirm(f"Add user '{CURRENT_USER}' to group(s) now?"):
|
||||
Logger.warn(
|
||||
"Skipped adding user to required groups. You might encounter issues."
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ from kiauh.utils.constants import COLOR_CYAN, RESET_FORMAT
|
||||
from kiauh.utils.logger import Logger
|
||||
|
||||
|
||||
def get_user_confirm(question: str, default_choice=True) -> bool:
|
||||
def get_confirm(question: str, default_choice=True) -> bool:
|
||||
options_confirm = ["y", "yes"]
|
||||
options_decline = ["n", "no"]
|
||||
|
||||
@@ -41,7 +41,7 @@ def get_user_confirm(question: str, default_choice=True) -> bool:
|
||||
Logger.print_error("Invalid choice. Please select 'y' or 'n'.")
|
||||
|
||||
|
||||
def get_user_number_input(
|
||||
def get_number_input(
|
||||
question: str, min_count: int, max_count=None, default=None
|
||||
) -> int:
|
||||
_question = question + f" (default={default})" if default else question
|
||||
@@ -65,7 +65,7 @@ def get_user_number_input(
|
||||
Logger.print_error("Invalid choice. Please select a valid number.")
|
||||
|
||||
|
||||
def get_user_string_input(question: str, exclude=Optional[List]) -> str:
|
||||
def get_string_input(question: str, exclude=Optional[List]) -> str:
|
||||
while True:
|
||||
_input = input(f"{COLOR_CYAN}###### {question}: {RESET_FORMAT}").strip()
|
||||
|
||||
@@ -77,7 +77,7 @@ def get_user_string_input(question: str, exclude=Optional[List]) -> str:
|
||||
Logger.print_error("This value is already in use/reserved.")
|
||||
|
||||
|
||||
def get_user_selection_input(question: str, option_list: List) -> str:
|
||||
def get_selection_input(question: str, option_list: List) -> str:
|
||||
while True:
|
||||
_input = input(f"{COLOR_CYAN}###### {question}: {RESET_FORMAT}").strip()
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from kiauh.utils.constants import COLOR_RED, RESET_FORMAT
|
||||
from kiauh.utils.input_utils import get_user_confirm
|
||||
from kiauh.utils.input_utils import get_confirm
|
||||
from kiauh.utils.logger import Logger
|
||||
|
||||
|
||||
@@ -56,9 +56,7 @@ def clone_repo(target_dir: Path, url: str, branch: str) -> None:
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Error cloning repository:", e.output.decode())
|
||||
else:
|
||||
overwrite_target = get_user_confirm(
|
||||
"Target directory already exists. Overwrite?"
|
||||
)
|
||||
overwrite_target = get_confirm("Target directory already exists. Overwrite?")
|
||||
if overwrite_target:
|
||||
try:
|
||||
shutil.rmtree(target_dir)
|
||||
@@ -98,7 +96,7 @@ def create_python_venv(target: Path) -> None:
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Error setting up virtualenv:", e.output.decode())
|
||||
else:
|
||||
overwrite_venv = get_user_confirm("Virtualenv already exists. Re-create?")
|
||||
overwrite_venv = get_confirm("Virtualenv already exists. Re-create?")
|
||||
if overwrite_venv:
|
||||
try:
|
||||
shutil.rmtree(target)
|
||||
|
||||
Reference in New Issue
Block a user