refactor: migrar comando new para que utilice metodos usando questionary

This commit is contained in:
jt
2026-07-14 00:22:22 -03:00
parent 4968667dad
commit a5a753f429
6 changed files with 104 additions and 55 deletions
+37 -8
View File
@@ -13,10 +13,10 @@ from git_flow.remote.gitea import GiteaRemoteAPI
from git_flow.io import *
from os.path import isfile
TYPE_SUCCESS = 0
TYPE_WARNING = 1
TYPE_ERROR = 2
TYPE_INFO = 3
from typing import Optional
import rich
import rich.panel
import questionary
flowconfig = Git.get_config(FLOWCONFIG_FILENAME) if isfile(FLOWCONFIG_FILENAME) else {}
@@ -48,7 +48,7 @@ def ensure_right_branch():
if branch == "HEAD":
raise GitFlowError("No se encuentra parado sobre una rama.")
elif confirm(f"Se encuentra sobre la rama '{branch}'. ¿Es correcto?"):
elif io_confirm(f"Se encuentra sobre la rama '{branch}'. ¿Es correcto?"):
return branch
else:
raise GitFlowError("Ejecución cancelada.")
@@ -102,11 +102,11 @@ def ensure_clean_worktree(has_remote: bool):
if not_empty:
if not has_remote:
warning("Existen cambios en tu entorno de trabajo sin commitear.")
io_warning("Existen cambios en tu entorno de trabajo sin commitear.")
else:
raise GitFlowError("No se puede continuar con cambios pendientes.")
if not confirm("¿Desea continuar?", False):
if not io_confirm("¿Desea continuar?", False):
raise GitFlowError("Ejecución abortada")
@@ -137,4 +137,33 @@ def is_valid_ticket(ticket: str) -> bool:
ticket_project = components[0]
ticket_number = components[1]
return ticket_project.isalpha() and ticket_project.isupper() and ticket_number.isnumeric()
return ticket_project.isalpha() and ticket_project.isupper() and ticket_number.isnumeric()
def io_error(message: str, title: Optional[str] = None):
_io_status(message, "❌ Error: ", "red", title)
def io_warning(message: str, title: Optional[str] = None):
_io_status(message, "⚠️ Warning: ", "yellow", title)
def io_info(message: str, title: Optional[str] = None):
_io_status(message, "️ Info: ", "blue", title)
def _io_status(message: str, prefix: str, style: str, title: Optional[str] = None):
if title:
rich.print(rich.panel.Panel(message, title=prefix + title, style=style, expand=False, title_align="left"))
else:
rich.print(f"[{style}]{prefix}{message}[/{style}]")
def io_confirm(question: str, default: bool = True) -> bool:
return questionary.confirm(question, default=default, auto_enter=False).ask()
def io_choice(prompt: str, options: list[str]) -> str:
return questionary.select(prompt, options, instruction="Usar flechas").ask()
def io_prompt(message: str, default: str = "", persistent: bool = False, strip: bool = False, validator = None) -> str:
if persistent and not validator:
validator = lambda s: len(s.strip()) > 0
value = questionary.text(message, default, validate=validator).ask()
return value.strip() if strip else value