summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--patternutils/commands/targs.py4
-rw-r--r--patternutils/commands/tln.py3
-rw-r--r--patternutils/commands/tmv.py3
-rw-r--r--patternutils/utils.py6
4 files changed, 10 insertions, 6 deletions
diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py
index 3da6552..317d5e1 100644
--- a/patternutils/commands/targs.py
+++ b/patternutils/commands/targs.py
@@ -105,7 +105,9 @@ def targs(
if editor:
try:
- commands = list(utils.edit(commands).values())
+ if (new_commands := utils.edit(commands)) is not None:
+ commands = list(new_commands.values())
+
except RuntimeError:
click.secho("Your edit is not parseable!", fg="red", err=True)
raise SystemExit
diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py
index 0033946..878f556 100644
--- a/patternutils/commands/tln.py
+++ b/patternutils/commands/tln.py
@@ -128,7 +128,8 @@ def tln(
if editor:
try:
- new_filenames = utils.edit(new_filenames)
+ if (temporary_filenames := utils.edit(new_filenames)) is not None:
+ new_filenames = temporary_filenames
except RuntimeError:
click.secho("Your edit is not parseable!", fg="red", err=True)
raise SystemExit
diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py
index 3b7f5e3..1c61b67 100644
--- a/patternutils/commands/tmv.py
+++ b/patternutils/commands/tmv.py
@@ -126,7 +126,8 @@ def tmv(
if editor:
try:
- new_filenames = utils.edit(new_filenames)
+ if (temporary_filenames := utils.edit(new_filenames)) is not None:
+ new_filenames = temporary_filenames
except RuntimeError:
click.secho("Your edit is not parseable!", fg="red", err=True)
raise SystemExit
diff --git a/patternutils/utils.py b/patternutils/utils.py
index ca07e2f..0395110 100644
--- a/patternutils/utils.py
+++ b/patternutils/utils.py
@@ -1,6 +1,6 @@
import json
import os
-from typing import Any, Generator, Union
+from typing import Any, Generator, Optional, Union
import click
@@ -10,7 +10,7 @@ def max_procs() -> int:
return 1 if cpu_count is None else cpu_count * 2
-def edit(data: Union[dict[str, str], list[str]]) -> dict[str, str]:
+def edit(data: Union[dict[str, str], list[str]]) -> Optional[dict[str, str]]:
longest = len(max(data, key=len))
@@ -31,7 +31,7 @@ def edit(data: Union[dict[str, str], list[str]]) -> dict[str, str]:
else:
raise RuntimeError
else:
- return data
+ return None
except click.UsageError:
click.secho("The editor could not be launced!", fg="red", err=True)
raise SystemExit