diff options
| author | Dennis Fink | 2022-02-25 19:11:55 +0100 |
|---|---|---|
| committer | Dennis Fink | 2022-02-25 19:11:55 +0100 |
| commit | 4f10bd7b7b03f8ebc02e715fac38e7b5d6e6047e (patch) | |
| tree | 708a7e13ca860f1c1d6d1d49c3bad5d37f9a2ec7 | |
| parent | 29989fd5fca9e42230557d7ffd5f6849433fd99f (diff) | |
| download | patternutils-4f10bd7b7b03f8ebc02e715fac38e7b5d6e6047e.tar.gz patternutils-4f10bd7b7b03f8ebc02e715fac38e7b5d6e6047e.zip | |
Added dry run option to targsv0.0.12
| -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 |
