feature: muevo opciones para check y print a metodos para ejecutar git
This commit is contained in:
+25
-23
@@ -22,7 +22,6 @@ class Git:
|
||||
self.file = line[3:].strip("\n")
|
||||
|
||||
command: list[str]
|
||||
check_returncode: bool = True
|
||||
|
||||
@staticmethod
|
||||
def get_config(file: str | None = None):
|
||||
@@ -60,7 +59,7 @@ class Git:
|
||||
|
||||
@staticmethod
|
||||
def get_current_tag():
|
||||
return Git("describe", abbrev="0", tags=True).without_checking().firstline()
|
||||
return Git("describe", abbrev="0", tags=True).firstline(check=False)
|
||||
|
||||
@staticmethod
|
||||
def get_first_fork_point(branch: str, env: str):
|
||||
@@ -115,44 +114,47 @@ class Git:
|
||||
|
||||
self.command += args
|
||||
|
||||
def lines(self, strip: bool = True):
|
||||
process = subprocess.run(self.command, capture_output=True, text=True)
|
||||
|
||||
self.__print_process(process.stdout, process.stderr)
|
||||
|
||||
if self.check_returncode:
|
||||
process.check_returncode()
|
||||
|
||||
def lines(self, strip: bool = True, **kwargs: bool):
|
||||
process = self._get(**kwargs)
|
||||
lines = process.stdout.splitlines()
|
||||
|
||||
return lines if not strip else list(map(lambda l: l.strip(), lines))
|
||||
|
||||
def firstline(self):
|
||||
lines = self.lines()
|
||||
def firstline(self, **kwargs: bool):
|
||||
lines = self.lines(**kwargs)
|
||||
|
||||
return lines[0] if lines else ""
|
||||
|
||||
def exec(self):
|
||||
def code(self, **kwargs):
|
||||
return self._run(check=False, **kwargs).returncode
|
||||
|
||||
def exec(self, **kwargs):
|
||||
self._run(**kwargs)
|
||||
|
||||
def _get(self, print: bool = False, check: bool = True):
|
||||
process = subprocess.run(self.command, capture_output=True, text=True)
|
||||
|
||||
self.__print_process(process.stdout, process.stderr)
|
||||
if print:
|
||||
self._print_process(process.stdout, process.stderr)
|
||||
|
||||
if self.check_returncode:
|
||||
if check:
|
||||
process.check_returncode()
|
||||
|
||||
def code(self):
|
||||
process = subprocess.run(self.command, capture_output=True, text=True)
|
||||
return process
|
||||
|
||||
self.__print_process(process.stdout, process.stderr)
|
||||
|
||||
return process.returncode
|
||||
def _run(self, print: bool = False, check: bool = True):
|
||||
process = subprocess.run(self.command)
|
||||
|
||||
def without_checking(self):
|
||||
self.check_returncode = False
|
||||
if print:
|
||||
self._print_process("", "")
|
||||
|
||||
return self
|
||||
if check:
|
||||
process.check_returncode()
|
||||
|
||||
def __print_process(self, stdout: str, stderr: str):
|
||||
return process
|
||||
|
||||
def _print_process(self, stdout: str, stderr: str):
|
||||
command = []
|
||||
|
||||
for arg in self.command:
|
||||
|
||||
Reference in New Issue
Block a user