summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--patternutils/config.py38
1 files changed, 18 insertions, 20 deletions
diff --git a/patternutils/config.py b/patternutils/config.py
index 583d111..016f7e2 100644
--- a/patternutils/config.py
+++ b/patternutils/config.py
@@ -10,27 +10,25 @@ CONFIG_PATH = click.get_app_dir('patternutils')
def load_template(template_name: str, command_name: str) -> Tuple[str, str]:
"""Load a template from the config directory."""
- try:
- files = find_templates(template_name, command_name)
- if len(files) == 1:
- with open(files[0], encoding='utf-8') as f:
- template_lines = f.read()
- elif len(files) == 0:
- raise FileNotFoundError
- elif len(files) > 1:
- raise RuntimeError('Multiple files found!')
- except (FileNotFoundError, RuntimeError):
- raise
+
+ files = find_templates(template_name, command_name)
+ if len(files) == 1:
+ with open(files[0], encoding='utf-8') as f:
+ template_lines = f.read()
+ elif len(files) == 0:
+ raise FileNotFoundError
+ elif len(files) > 1:
+ raise RuntimeError('Multiple files found!')
+
+ output_pattern = template_lines.replace('\n', '')
+ template_file = files[0]
+ if template_file.endswith('regex'):
+ template_engine = 'regex'
+ elif template_file.endswith('jinja2'):
+ template_engine = 'jinja2'
else:
- output_pattern = template_lines.replace('\n', '')
- template_file = files[0]
- if template_file.endswith('regex'):
- template_engine = 'regex'
- elif template_file.endswith('jinja2'):
- template_engine = 'jinja2'
- else:
- template_engine = 'python'
- return output_pattern, template_engine
+ template_engine = 'python'
+ return output_pattern, template_engine
def find_templates(template_name: str, command_name: str=None) -> List[str]: