diff options
| author | Dennis Fink | 2025-07-14 14:57:18 +0200 |
|---|---|---|
| committer | Dennis Fink | 2025-07-14 14:57:18 +0200 |
| commit | 7f98df02693578f69266e8f2630a50787bc06041 (patch) | |
| tree | 39045932820b0823bef6a7970f3e92cac578f617 | |
| parent | 7b9bc9a8703fa3fe6687902fe1f3d8ecb74a6b1e (diff) | |
| download | patternutils-7f98df02693578f69266e8f2630a50787bc06041.tar.gz patternutils-7f98df02693578f69266e8f2630a50787bc06041.zip | |
Simplify find template
| -rw-r--r-- | patternutils/config.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/patternutils/config.py b/patternutils/config.py index fab41be..7f67f03 100644 --- a/patternutils/config.py +++ b/patternutils/config.py @@ -45,14 +45,16 @@ def load_template( """ files = find_templates(template_name, command_name) - if len(files) == 1: - template_file = files[0] - with open(template_file, encoding="utf-8") as f: - template_lines = f.read() - elif not files: - raise FileNotFoundError - elif len(files) > 1: - raise RuntimeError("Multiple files found!") + + if not files: + raise FileNotFoundError(f"No template found for '{template_name}'.") + + if len(files) > 1: + raise RuntimeError(f"Multiple template files found for '{template_name}'.") + + template_file = files[0] + with open(template_file, encoding="utf-8") as f: + template_lines = f.read() output_pattern = template_lines.replace("\n", "") extension = os.path.splitext(template_file)[1][1:].lower() |
