summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--patternutils/utils.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/patternutils/utils.py b/patternutils/utils.py
index d78d990..ca07e2f 100644
--- a/patternutils/utils.py
+++ b/patternutils/utils.py
@@ -19,18 +19,22 @@ def edit(data: Union[dict[str, str], list[str]]) -> dict[str, str]:
else:
temporary = [f"{value.ljust(longest)}\t{value}\n" for value in data]
- if (edited := click.edit("".join(temporary))) is not None:
- new_data = dict()
- for line in edited.split("\n"):
- if line and "\t" in line:
- old, new = line.split("\t")
- new_data[old.strip()] = new
- if new_data:
- return new_data
+ try:
+ if (edited := click.edit("".join(temporary))) is not None:
+ new_data = dict()
+ for line in edited.split("\n"):
+ if line and "\t" in line:
+ old, new = line.split("\t")
+ new_data[old.strip()] = new
+ if new_data:
+ return new_data
+ else:
+ raise RuntimeError
else:
- raise RuntimeError
- else:
- return data
+ return data
+ except click.UsageError:
+ click.secho("The editor could not be launced!", fg="red", err=True)
+ raise SystemExit
def json_dumps(data: Any, human_readable: bool = False) -> str: