81 lines
2.1 KiB
Python
Executable File
81 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from subprocess import CalledProcessError, SubprocessError
|
|
from typing import Annotated
|
|
|
|
import click
|
|
import typer
|
|
from rich.markup import escape
|
|
from rich.traceback import Traceback
|
|
|
|
from git_flow import GitFlowError
|
|
from git_flow.command import base, branch, commit, init, merge, new, release, tag
|
|
from git_flow.io import console, settings
|
|
|
|
REPOSITORY_TOKEN_PATH = ".repository-token"
|
|
LOCALE = "es_AR.UTF-8"
|
|
|
|
|
|
app = typer.Typer()
|
|
app.add_typer(init.app)
|
|
app.add_typer(new.app)
|
|
app.add_typer(commit.app)
|
|
app.add_typer(merge.app)
|
|
app.add_typer(tag.app)
|
|
app.add_typer(release.app)
|
|
app.add_typer(branch.app)
|
|
|
|
|
|
@app.callback()
|
|
def options(
|
|
verbose: Annotated[
|
|
bool,
|
|
typer.Option(
|
|
"--verbose",
|
|
"-v",
|
|
help="Muestra la salida de los comandos git y el traceback de los errores",
|
|
),
|
|
] = False,
|
|
):
|
|
settings.verbose = verbose
|
|
|
|
|
|
def main():
|
|
try:
|
|
app()
|
|
print()
|
|
except GitFlowError as e:
|
|
_print_error(escape(str(e)), "Git Flow", e)
|
|
except CalledProcessError as e:
|
|
_print_error(_format_process_error(e), "Comando", e)
|
|
except SubprocessError as e:
|
|
_print_error(escape(str(e)), "Comando", e)
|
|
except KeyboardInterrupt:
|
|
base.io_error("Ejecución abortada")
|
|
|
|
|
|
def _format_process_error(e: CalledProcessError) -> str:
|
|
command = " ".join(e.cmd) if isinstance(e.cmd, list) else str(e.cmd)
|
|
message = f"[bold]$ {escape(command)}[/bold]\nTerminó con código de salida {e.returncode}"
|
|
|
|
for output in (e.stdout, e.stderr):
|
|
if isinstance(output, str) and output.strip():
|
|
message += "\n\n" + escape(output.strip())
|
|
|
|
return message
|
|
|
|
|
|
def _print_error(message: str, title: str, e: BaseException):
|
|
if settings.verbose:
|
|
base.io_error(message, title=title)
|
|
console.print(
|
|
Traceback.from_exception(
|
|
type(e), e, e.__traceback__, suppress=[click, typer]
|
|
)
|
|
)
|
|
else:
|
|
base.io_error(
|
|
message + "\n\n[dim]Ejecutar con `git-flow --verbose <comando>` para ver el detalle[/dim]",
|
|
title=title,
|
|
)
|