From 07699b08eb6a89e0e14455c443e2c8408d40c0c6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 20:47:49 +0200 Subject: [PATCH] ps/items --- rwx/ps/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index b2eca55..1bb552d 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -5,10 +5,10 @@ import subprocess from rwx import txt -def get_tuples_args(*tuples: tuple[str]) -> list[str]: +def get_tuples_args(*items: str | tuple[str]) -> list[str]: """Turn arguments tuples into an arguments list.""" args: list[str] = [] - for item in tuples: + for item in items: if type(item) is tuple: args.extend(item) else: @@ -16,23 +16,25 @@ def get_tuples_args(*tuples: tuple[str]) -> list[str]: return args -def run(*tuples: tuple[str]) -> subprocess.CompletedProcess: +def run(*items: str | tuple[str]) -> subprocess.CompletedProcess: """Run from a list of arguments tuples.""" return subprocess.run( - get_tuples_args(tuples), capture_output=False, check=True + get_tuples_args(*items), capture_output=False, check=True ) -def run_line(*tuples: tuple[str], charset: str = txt.CHARSET) -> str: +def run_line(*items: str | tuple[str], charset: str = txt.CHARSET) -> str: """Run and return output line.""" - lines = run_lines(*get_tuples_args(tuples), charset=charset) + lines = run_lines(get_tuples_args(*items), charset=charset) return lines[0] -def run_lines(*tuples: tuple[str], charset: str = txt.CHARSET) -> list[str]: +def run_lines( + *items: str | tuple[str], charset: str = txt.CHARSET +) -> list[str]: """Run and return output lines.""" process = subprocess.run( - get_tuples_args(tuples), capture_output=True, check=True + get_tuples_args(*items), capture_output=True, check=True ) string = process.stdout.decode(charset) return string.rstrip().splitlines()