diff options
| -rw-r--r-- | patternutils/commands/targs.py | 26 |
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 |
