57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
import sys
|
|
|
|
from git_flow import COLOR_BLACK_BOLD, COLOR_BLUE, COLOR_GREEN, COLOR_RED, COLOR_RESET, COLOR_YELLOW
|
|
|
|
def confirm(prompt, default: bool = True):
|
|
user_input = input(prompt + (" [Y/n]: " if default else " [y/N]: "))
|
|
|
|
return default if len(user_input) == 0 else user_input.startswith("y")
|
|
|
|
|
|
def choose(prompt: str, options: list[str]):
|
|
print(prompt)
|
|
|
|
for i, option in enumerate(options):
|
|
print(f"\t{i+1}. {option}")
|
|
|
|
selection = None
|
|
|
|
while selection is None:
|
|
user_input = input(f"Seleccione una opción [1-{len(options)}] o escribala: ")
|
|
|
|
if user_input.isdigit():
|
|
user_input = int(user_input)
|
|
|
|
if 1 <= user_input and user_input <= len(options):
|
|
selection = options[user_input - 1]
|
|
|
|
if not confirm(
|
|
f"Seleccionó la opción {user_input} ({selection}), ¿es correcto?"
|
|
):
|
|
selection = None
|
|
else:
|
|
print_error(f"La opción {user_input} está fuera del rango permitido.")
|
|
elif user_input in options:
|
|
selection = user_input
|
|
else:
|
|
print_error(f"La opción '{user_input}' es inválida.")
|
|
|
|
return selection
|
|
|
|
|
|
def print_error(message: str):
|
|
print(f"{COLOR_RED}[err] {message}{COLOR_RESET}", file=sys.stderr)
|
|
|
|
|
|
def print_warning(message: str):
|
|
print(f"{COLOR_YELLOW}[wrn] {message}{COLOR_RESET}")
|
|
|
|
def print_success(message: str):
|
|
print(f"{COLOR_GREEN}[ok!] {message}{COLOR_RESET}")
|
|
|
|
def print_info(message: str):
|
|
print(f"{COLOR_BLUE}[inf] {message}{COLOR_RESET}")
|
|
|
|
def print_debug(message: str):
|
|
print(f"{COLOR_BLACK_BOLD}[dbg] {message}{COLOR_RESET}")
|