summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2022-02-25 19:11:55 +0100
committerDennis Fink2022-02-25 19:11:55 +0100
commit4f10bd7b7b03f8ebc02e715fac38e7b5d6e6047e (patch)
tree708a7e13ca860f1c1d6d1d49c3bad5d37f9a2ec7
parent29989fd5fca9e42230557d7ffd5f6849433fd99f (diff)
downloadpatternutils-4f10bd7b7b03f8ebc02e715fac38e7b5d6e6047e.tar.gz
patternutils-4f10bd7b7b03f8ebc02e715fac38e7b5d6e6047e.zip
Added dry run option to targsv0.0.12
Diffstat (limited to '')
-rw-r--r--patternutils/commands/targs.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py
index 947061f..34cf018 100644
--- a/patternutils/commands/targs.py
+++ b/patternutils/commands/targs.py
@@ -64,6 +64,13 @@ def run_command(
default=False,
help="Open an editor before running commands to allow manual changes",
)
+@click.option(
+ "-n",
+ "--dry-run",
+ is_flag=True,
+ default=False,
+ help="perform a trial run without actually executing the command",
+)
@click.version_option()
@click.argument("command")
def targs(
@@ -78,6 +85,7 @@ def targs(
stream: bool,
editor: bool,
verbose: bool,
+ dry_run: bool,
) -> None:
"""Execute commands based on a template string.
@@ -126,11 +134,19 @@ def targs(
stdout=stdout,
stderr=stderr,
)
- patched_run_command = functools.partial(
- run_command,
- run=patched_subprocess,
- shell=shell,
- )
+
+ if not dry_run:
+ patched_run_command = functools.partial(
+ run_command,
+ run=patched_subprocess,
+ shell=shell,
+ )
+ else:
+ patched_run_command = functools.partial(
+ run_command,
+ run=print,
+ shell=True,
+ )
max_procs = utils.max_procs() if max_procs == 0 else max_procs