bugfix: cambiando tipo de print para agregar soporte de titulos
This commit is contained in:
+13
-11
@@ -114,7 +114,7 @@ class Git:
|
||||
|
||||
self.command += args
|
||||
|
||||
def lines(self, strip: bool = True, **kwargs: bool):
|
||||
def lines(self, strip: bool = True, **kwargs):
|
||||
process = self._get(**kwargs)
|
||||
lines = process.stdout.splitlines()
|
||||
|
||||
@@ -131,11 +131,11 @@ class Git:
|
||||
def exec(self, **kwargs):
|
||||
self._run(**kwargs)
|
||||
|
||||
def _get(self, print: bool = False, check: bool = True):
|
||||
def _get(self, print: str|None = None, check: bool = True):
|
||||
process = subprocess.run(self.command, capture_output=True, text=True)
|
||||
|
||||
if print:
|
||||
self._print_process(process.stdout, process.stderr)
|
||||
if print is not None:
|
||||
self._print_process(process.stdout, process.stderr, print)
|
||||
|
||||
if check:
|
||||
process.check_returncode()
|
||||
@@ -143,18 +143,18 @@ class Git:
|
||||
return process
|
||||
|
||||
|
||||
def _run(self, print: bool = False, check: bool = True):
|
||||
def _run(self, print: str|None = None, check: bool = True):
|
||||
process = subprocess.run(self.command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
if print:
|
||||
self._print_process("", "")
|
||||
if print is not None:
|
||||
self._print_process("", "", title=print)
|
||||
|
||||
if check:
|
||||
process.check_returncode()
|
||||
|
||||
return process
|
||||
|
||||
def _print_process(self, stdout: str, stderr: str):
|
||||
def _print_process(self, stdout: str, stderr: str, title: str):
|
||||
command = []
|
||||
|
||||
for arg in self.command:
|
||||
@@ -166,10 +166,12 @@ class Git:
|
||||
|
||||
command.append(arg)
|
||||
|
||||
print(COLOR_YELLOW + "> " + " ".join(command) + COLOR_RESET)
|
||||
title = title or "Ejecutando"
|
||||
print(COLOR_YELLOW + "| " + title + COLOR_RESET)
|
||||
print(COLOR_YELLOW + "| $ " + " ".join(command) + COLOR_RESET)
|
||||
|
||||
for line in stdout.splitlines():
|
||||
print(COLOR_BLUE + "< " + line + COLOR_RESET)
|
||||
print(COLOR_YELLOW + "| " + COLOR_RESET + "[out] " + line)
|
||||
|
||||
for line in stderr.splitlines():
|
||||
print(COLOR_RED + "! " + line + COLOR_RESET)
|
||||
print(COLOR_YELLOW + "| " + COLOR_RED + "[err] " + line + COLOR_RESET)
|
||||
|
||||
Reference in New Issue
Block a user