From 5ddcb6231032cf566b0dd45e84aa52b85ed559d6 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 25 Sep 2020 21:24:13 +0200 Subject: Add editor options to targs --- patternutils/commands/targs.py | 21 +++++++++++++++++++-- 1 file 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__": -- cgit v1.3.1