summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2025-07-14 14:58:48 +0200
committerDennis Fink2025-07-14 14:58:48 +0200
commitfd05c120f5fc0db663c3a9b7a99c0b9c2216cbcb (patch)
tree3ed639b92bce4a2c139a5408ae8d4135494c0465
parent6062fa5cc245d709c74ec7b6b9e2ed0af3f70224 (diff)
downloadpatternutils-fd05c120f5fc0db663c3a9b7a99c0b9c2216cbcb.tar.gz
patternutils-fd05c120f5fc0db663c3a9b7a99c0b9c2216cbcb.zip
Add --abort-on-key-not-found in tmv
Diffstat (limited to '')
-rw-r--r--patternutils/commands/tmv.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py
index 4fda28c..150f67d 100644
--- a/patternutils/commands/tmv.py
+++ b/patternutils/commands/tmv.py
@@ -79,6 +79,12 @@ def move_file(old_filename: str, new_filename: str) -> 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,
@@ -101,6 +107,7 @@ def tmv(
force: bool,
template_engine: template.TemplateEngines,
abort_on_path_exist: bool,
+ abort_on_key_not_found: bool,
use_predefined_template: bool,
read_from: TextIO,
key: str,
@@ -145,7 +152,12 @@ def tmv(
click.secho("Jinja2 not installed!", fg="red", err=True)
raise SystemExit(1)
- new_filenames = dict((entry[key], render(**entry)) for entry in data)
+ try:
+ new_filenames = {entry[key]: render(**entry) for entry in data}
+ 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: