refactor: remove unused constants, move io functions to module
This commit is contained in:
@@ -49,15 +49,3 @@ SUPPORTED_REMOTE_APIS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
REPOSITORY_TOKEN_FILENAME = ".repository-token"
|
REPOSITORY_TOKEN_FILENAME = ".repository-token"
|
||||||
|
|
||||||
COLOR_BLACK = "\033[30m"
|
|
||||||
COLOR_RED = "\033[31m"
|
|
||||||
COLOR_GREEN = "\033[32m"
|
|
||||||
COLOR_YELLOW = "\033[33m"
|
|
||||||
COLOR_BLUE = "\033[34m"
|
|
||||||
COLOR_5 = "\033[35m"
|
|
||||||
COLOR_6 = "\033[36m"
|
|
||||||
COLOR_7 = "\033[37m"
|
|
||||||
COLOR_BLACK_BOLD = "\033[1;30m"
|
|
||||||
COLOR_WHITE_BOLD = "\033[1;37m"
|
|
||||||
COLOR_RESET = "\033[0m"
|
|
||||||
|
|||||||
@@ -7,70 +7,18 @@ from git_flow.git import FLOWCONFIG_FILE, Git
|
|||||||
from git_flow.remote.base import RemoteAPI
|
from git_flow.remote.base import RemoteAPI
|
||||||
from git_flow.remote.bitbucket import BitbucketRemoteAPI
|
from git_flow.remote.bitbucket import BitbucketRemoteAPI
|
||||||
from git_flow.remote.github import GithubRemoteAPI
|
from git_flow.remote.github import GithubRemoteAPI
|
||||||
|
from git_flow.io import *
|
||||||
from os.path import isfile
|
from os.path import isfile
|
||||||
from rich.console import Console
|
|
||||||
from rich.prompt import Prompt, Confirm
|
|
||||||
from rich.panel import Panel
|
|
||||||
|
|
||||||
TYPE_SUCCESS = 0
|
TYPE_SUCCESS = 0
|
||||||
TYPE_WARNING = 1
|
TYPE_WARNING = 1
|
||||||
TYPE_ERROR = 2
|
TYPE_ERROR = 2
|
||||||
TYPE_INFO = 3
|
TYPE_INFO = 3
|
||||||
|
|
||||||
console = Console(highlight=False)
|
|
||||||
flowconfig = Git.get_config(FLOWCONFIG_FILE) if isfile(FLOWCONFIG_FILE) else {}
|
flowconfig = Git.get_config(FLOWCONFIG_FILE) if isfile(FLOWCONFIG_FILE) else {}
|
||||||
|
|
||||||
|
|
||||||
def success(msg: str):
|
|
||||||
console.print(f":white_check_mark: [green]{msg}[/green]")
|
|
||||||
|
|
||||||
|
|
||||||
def warning(msg: str):
|
|
||||||
console.print(f":warning: [yellow]{msg}[/yellow]")
|
|
||||||
|
|
||||||
|
|
||||||
def error(msg: str):
|
|
||||||
console.print(f":x: [red]{msg}[/red]")
|
|
||||||
|
|
||||||
|
|
||||||
def info(msg: str):
|
|
||||||
console.print(f":information: [blue]{msg}[/blue]")
|
|
||||||
|
|
||||||
|
|
||||||
def panel(title: str, text: str):
|
|
||||||
console.print(Panel(text, title=title, expand=False, title_align="left"))
|
|
||||||
|
|
||||||
|
|
||||||
def prompt(
|
|
||||||
prompt: str,
|
|
||||||
default: str | None = None,
|
|
||||||
persistent: bool = False,
|
|
||||||
strip: bool = True,
|
|
||||||
) -> str:
|
|
||||||
onetime = not persistent
|
|
||||||
|
|
||||||
while onetime or persistent:
|
|
||||||
result = Prompt.ask(prompt)
|
|
||||||
result = result.strip() if strip else result
|
|
||||||
|
|
||||||
if result:
|
|
||||||
return result
|
|
||||||
elif default is not None:
|
|
||||||
return default
|
|
||||||
elif persistent:
|
|
||||||
error("Debe ingresar un valor no vacío.")
|
|
||||||
else:
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def confirm(question: str, default: bool = True):
|
|
||||||
return Confirm.ask(question, default=default)
|
|
||||||
|
|
||||||
|
|
||||||
def choice(prompt: str, options: list[str]):
|
|
||||||
return Prompt.ask(prompt, choices=options)
|
|
||||||
|
|
||||||
|
|
||||||
def ensure_initialized():
|
def ensure_initialized():
|
||||||
initialized = flowconfig["flow.initialized"] if flowconfig else None
|
initialized = flowconfig["flow.initialized"] if flowconfig else None
|
||||||
|
|
||||||
|
|||||||
+13
-12
@@ -1,9 +1,7 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from git_flow import GitFlowError
|
|
||||||
from git_flow.io import *
|
from git_flow.io import *
|
||||||
|
|
||||||
|
|
||||||
FLOWCONFIG_FILE = ".flowconfig"
|
FLOWCONFIG_FILE = ".flowconfig"
|
||||||
|
|
||||||
CHANGELOG_FILE = "CHANGELOG.md"
|
CHANGELOG_FILE = "CHANGELOG.md"
|
||||||
@@ -88,7 +86,9 @@ class Git:
|
|||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __init__(self, subcommand: str, *args: str, **kwargs: str | int | bool | list[str] | None) -> None:
|
def __init__(
|
||||||
|
self, subcommand: str, *args: str, **kwargs: str | int | bool | list[str] | None
|
||||||
|
) -> None:
|
||||||
self.command = ["git", subcommand]
|
self.command = ["git", subcommand]
|
||||||
|
|
||||||
for option, value in kwargs.items():
|
for option, value in kwargs.items():
|
||||||
@@ -133,7 +133,7 @@ class Git:
|
|||||||
def exec(self, **kwargs):
|
def exec(self, **kwargs):
|
||||||
self._run(**kwargs)
|
self._run(**kwargs)
|
||||||
|
|
||||||
def _get(self, print: str|None = None, check: bool = True):
|
def _get(self, print: str | None = None, check: bool = True):
|
||||||
process = subprocess.run(self.command, capture_output=True, text=True)
|
process = subprocess.run(self.command, capture_output=True, text=True)
|
||||||
|
|
||||||
if print is not None:
|
if print is not None:
|
||||||
@@ -144,9 +144,10 @@ class Git:
|
|||||||
|
|
||||||
return process
|
return process
|
||||||
|
|
||||||
|
def _run(self, print: str | None = None, check: bool = True):
|
||||||
def _run(self, print: str|None = None, check: bool = True):
|
process = subprocess.run(
|
||||||
process = subprocess.run(self.command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
self.command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
|
|
||||||
if print is not None:
|
if print is not None:
|
||||||
self._print_process("", "", title=print)
|
self._print_process("", "", title=print)
|
||||||
@@ -168,12 +169,12 @@ class Git:
|
|||||||
|
|
||||||
command.append(arg)
|
command.append(arg)
|
||||||
|
|
||||||
title = title or "Ejecutando"
|
text = f"[yellow]$ {" ".join(command)}[/yellow]"
|
||||||
print(COLOR_YELLOW + "| " + title + COLOR_RESET)
|
|
||||||
print(COLOR_YELLOW + "| $ " + " ".join(command) + COLOR_RESET)
|
|
||||||
|
|
||||||
for line in stdout.splitlines():
|
for line in stdout.splitlines():
|
||||||
print(COLOR_YELLOW + "| " + COLOR_RESET + "[out] " + line)
|
text += "\n\\[out] " + line
|
||||||
|
|
||||||
for line in stderr.splitlines():
|
for line in stderr.splitlines():
|
||||||
print(COLOR_YELLOW + "| " + COLOR_RED + "[err] " + line + COLOR_RESET)
|
text += "\n[red]\\[err][/red] " + line
|
||||||
|
|
||||||
|
panel(title or "Ejecutando", text)
|
||||||
|
|||||||
+41
-42
@@ -1,56 +1,55 @@
|
|||||||
import sys
|
from rich.console import Console
|
||||||
|
from rich.prompt import Prompt, Confirm
|
||||||
|
from rich.panel import Panel
|
||||||
|
|
||||||
from git_flow import COLOR_BLACK_BOLD, COLOR_BLUE, COLOR_GREEN, COLOR_RED, COLOR_RESET, COLOR_YELLOW
|
console = Console(highlight=False)
|
||||||
|
|
||||||
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]):
|
def success(msg: str):
|
||||||
print(prompt)
|
console.print(f":white_check_mark: [green]{msg}[/green]")
|
||||||
|
|
||||||
for i, option in enumerate(options):
|
|
||||||
print(f"\t{i+1}. {option}")
|
|
||||||
|
|
||||||
selection = None
|
def warning(msg: str):
|
||||||
|
console.print(f":warning: [yellow]{msg}[/yellow]")
|
||||||
|
|
||||||
while selection is None:
|
|
||||||
user_input = input(f"Seleccione una opción [1-{len(options)}] o escribala: ")
|
|
||||||
|
|
||||||
if user_input.isdigit():
|
def error(msg: str):
|
||||||
user_input = int(user_input)
|
console.print(f":x: [red]{msg}[/red]")
|
||||||
|
|
||||||
if 1 <= user_input and user_input <= len(options):
|
|
||||||
selection = options[user_input - 1]
|
|
||||||
|
|
||||||
if not confirm(
|
def info(msg: str):
|
||||||
f"Seleccionó la opción {user_input} ({selection}), ¿es correcto?"
|
console.print(f":information: [blue]{msg}[/blue]")
|
||||||
):
|
|
||||||
selection = None
|
|
||||||
else:
|
def panel(title: str, text: str):
|
||||||
print_error(f"La opción {user_input} está fuera del rango permitido.")
|
console.print(Panel(text, title=title, expand=False, title_align="left"))
|
||||||
elif user_input in options:
|
|
||||||
selection = user_input
|
|
||||||
|
def prompt(
|
||||||
|
prompt: str,
|
||||||
|
default: str | None = None,
|
||||||
|
persistent: bool = False,
|
||||||
|
strip: bool = True,
|
||||||
|
) -> str:
|
||||||
|
onetime = not persistent
|
||||||
|
|
||||||
|
while onetime or persistent:
|
||||||
|
result = Prompt.ask(prompt)
|
||||||
|
result = result.strip() if strip else result
|
||||||
|
|
||||||
|
if result:
|
||||||
|
return result
|
||||||
|
elif default is not None:
|
||||||
|
return default
|
||||||
|
elif persistent:
|
||||||
|
error("Debe ingresar un valor no vacío.")
|
||||||
else:
|
else:
|
||||||
print_error(f"La opción '{user_input}' es inválida.")
|
return result
|
||||||
|
|
||||||
return selection
|
|
||||||
|
|
||||||
|
|
||||||
def print_error(message: str):
|
def confirm(question: str, default: bool = True):
|
||||||
print(f"{COLOR_RED}[err] {message}{COLOR_RESET}", file=sys.stderr)
|
return Confirm.ask(question, default=default)
|
||||||
|
|
||||||
|
|
||||||
def print_warning(message: str):
|
def choice(prompt: str, options: list[str]):
|
||||||
print(f"{COLOR_YELLOW}[wrn] {message}{COLOR_RESET}")
|
return Prompt.ask(prompt, choices=options)
|
||||||
|
|
||||||
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}")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user