summaryrefslogtreecommitdiff
path: root/patternutils
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--patternutils/commands/targs.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py
index 0aee69f..ad7e047 100644
--- a/patternutils/commands/targs.py
+++ b/patternutils/commands/targs.py
@@ -20,9 +20,8 @@ import patternutils
def run_command(
data: Dict[str, str],
render: Callable[..., str],
- shell: bool=False,
- redirect_stdout: bool=False,
- redirect_stderr: bool=False,
+ run: Callable[..., None],
+ shell: bool,
) -> None:
c = render(**data)
if not shell:
@@ -30,9 +29,7 @@ def run_command(
else:
prepared_command = c
- stdout = subprocess.DEVNULL if redirect_stdout else None
- stderr = subprocess.DEVNULL if redirect_stderr else None
- subprocess.run(prepared_command, shell=shell, stderr=stderr, stdout=stdout)
+ run(prepared_command)
@click.command(context_settings={'help_option_names': ('-h', '--help', '-?')})
@@ -76,12 +73,19 @@ def targs(
max_procs = os.cpu_count() * 2 if max_procs == 0 else max_procs
+ stdout = subprocess.DEVNULL if redirect_stdout else None
+ stderr = subprocess.DEVNULL if redirect_stderr else None
+ patched_subprocess = functools.partial(
+ subprocess.run,
+ shell=shell,
+ stout=stdout,
+ stderr=stderr,
+ )
patched_run_command = functools.partial(
run_command,
render=render,
+ run=patched_subprocess,
shell=shell,
- redirect_stderr=redirect_stderr,
- redirect_stdout=redirect_stdout,
)
if max_procs == 1:
for r in data: