Compare commits

..

No commits in common. "c024c553b0df3c7f1ea0f2c248b95c407d9ac46c" and "bf1b3402ae58e9f0bb97259e8e016c5c8d7841aa" have entirely different histories.

View file

@ -5,10 +5,10 @@ import subprocess
from rwx import txt from rwx import txt
def get_tuples_args(*items: str | tuple[str]) -> list[str]: def get_tuples_args(*tuples: tuple[str]) -> list[str]:
"""Turn arguments tuples into an arguments list.""" """Turn arguments tuples into an arguments list."""
args: list[str] = [] args: list[str] = []
for item in items: for item in tuples:
if type(item) is tuple: if type(item) is tuple:
args.extend(item) args.extend(item)
else: else:
@ -16,25 +16,23 @@ def get_tuples_args(*items: str | tuple[str]) -> list[str]:
return args return args
def run(*items: str | tuple[str]) -> subprocess.CompletedProcess: def run(*tuples: tuple[str]) -> subprocess.CompletedProcess:
"""Run from a list of arguments tuples.""" """Run from a list of arguments tuples."""
return subprocess.run( return subprocess.run(
get_tuples_args(*items), capture_output=False, check=True get_tuples_args(tuples), capture_output=False, check=True
) )
def run_line(*items: str | tuple[str], charset: str = txt.CHARSET) -> str: def run_line(*tuples: tuple[str], charset: str = txt.CHARSET) -> str:
"""Run and return output line.""" """Run and return output line."""
lines = run_lines(*items, charset=charset) lines = run_lines(*get_tuples_args(tuples), charset=charset)
return lines[0] return lines[0]
def run_lines( def run_lines(*tuples: tuple[str], charset: str = txt.CHARSET) -> list[str]:
*items: str | tuple[str], charset: str = txt.CHARSET
) -> list[str]:
"""Run and return output lines.""" """Run and return output lines."""
process = subprocess.run( process = subprocess.run(
get_tuples_args(*items), capture_output=True, check=True get_tuples_args(tuples), capture_output=True, check=True
) )
string = process.stdout.decode(charset) string = process.stdout.decode(charset)
return string.rstrip().splitlines() return string.rstrip().splitlines()