summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2020-09-25 21:24:13 +0200
committerDennis Fink2020-09-25 21:24:13 +0200
commit5ddcb6231032cf566b0dd45e84aa52b85ed559d6 (patch)
tree077afb5c1cfa5fbc6ebd0a5791c3ec9f46ede451
parentc6ea4f1780d3366cbece5e8267d4fd96dc240e5a (diff)
downloadpatternutils-5ddcb6231032cf566b0dd45e84aa52b85ed559d6.tar.gz
patternutils-5ddcb6231032cf566b0dd45e84aa52b85ed559d6.zip
Add editor options to targs
Diffstat (limited to '')
-rw-r--r--patternutils/commands/targs.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py
index 79d906d..04c286d 100644
--- a/patternutils/commands/targs.py
+++ b/patternutils/commands/targs.py
@@ -62,6 +62,13 @@ def run_command(
@click.option(
"--stream", is_flag=True, default=False, help="Input is a stream of JSON objects"
)
+@click.option(
+ "-e",
+ "--editor",
+ is_flag=True,
+ default=False,
+ help="Open an editor before running commands to allow manual changes",
+)
@click.version_option()
@click.argument("command")
def targs(
@@ -74,6 +81,7 @@ def targs(
redirect_stderr: bool,
use_predefined_template: bool,
stream: bool,
+ editor: bool,
verbose: bool,
) -> None:
@@ -102,6 +110,15 @@ def targs(
click.secho("jinja2 not installed!", fg="red", err=True)
raise SystemExit
+ commands = [render(r) for r in data]
+
+ if editor:
+ try:
+ commands = utils.edit(commands)
+ except RuntimeErro:
+ click.secho("Your edit is not parseable!", fg="red", err=True)
+ raise SystemExit
+
max_procs = utils.max_procs() if max_procs == 0 else max_procs
stdout = subprocess.DEVNULL if redirect_stdout else None
@@ -118,11 +135,11 @@ def targs(
shell=shell,
)
if max_procs == 1:
- for r in data:
+ for r in commands:
patched_run_command(r)
else:
with multiprocessing.Pool(max_procs) as p:
- p.map(patched_run_command, data)
+ p.map(patched_run_command, commands)
if __name__ == "__main__":