diff options
Diffstat (limited to '')
| -rw-r--r-- | patternutils/commands/targs.py | 11 | ||||
| -rw-r--r-- | patternutils/commands/tln.py | 27 | ||||
| -rw-r--r-- | patternutils/commands/tmv.py | 13 |
3 files changed, 29 insertions, 22 deletions
diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index b6fc509..a4f91e0 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -143,12 +143,11 @@ def targs( ) raise SystemExit(1) - try: - render = template.get_render_function(command, "targs", engine=template_engine) - except RuntimeError: - click.secho("Jinja2 not installed!", fg="red", err=True) - raise SystemExit(1) - + render = template.get_render_function( + command, + "targs", + engine=template_engine, + ) commands = [render(r) for r in data] if editor: diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index 4e1e616..cd2d4fe 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -86,6 +86,12 @@ def link_file(source: str, destination: str, symbolic: bool) -> None: help="exit if a renamed path already exists", ) @click.option( + "--abort-on-key-not-found", + is_flag=True, + default=False, + help="Exit if the specified key (specified by the --key option) is not found in the input JSON.", +) +@click.option( "-n", "--dry-run", is_flag=True, @@ -113,6 +119,7 @@ def tln( key: str, stream: bool, abort_on_path_exist: bool, + abort_on_key_not_found: bool, dry_run: bool, verbose: bool, ) -> None: @@ -134,15 +141,19 @@ def tln( click.secho("Multiple files found!", fg="red", err=True) raise SystemExit + render = template.get_render_function( + output_pattern, + "tln", + engine=template_engine, + ) + new_filenames = dict() try: - render = template.get_render_function( - output_pattern, "tln", engine=template_engine - ) - except RuntimeError: - click.secho("jinja2 not installed!", fg="red", err=True) - raise SystemExit - - new_filenames = dict((entry["_abspath"], render(**entry)) for entry in data) + for entry in data: + new_filenames[entry[key]] = render(**entry) + except KeyError: + click.secho(f"Key '{key}' not found in input data.", fg="red", err=True) + if abort_on_key_not_found: + raise SystemExit(1) if editor: try: diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py index 7ddcf8e..58a75e5 100644 --- a/patternutils/commands/tmv.py +++ b/patternutils/commands/tmv.py @@ -147,14 +147,11 @@ def tmv( ) raise SystemExit(1) - try: - render = template.get_render_function( - output_pattern, "tmv", engine=template_engine - ) - except RuntimeError: - click.secho("Jinja2 not installed!", fg="red", err=True) - raise SystemExit(1) - + render = template.get_render_function( + output_pattern, + "tmv", + engine=template_engine, + ) new_filenames = dict() try: for entry in data: |
