summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--patternutils/commands/pmatch.py9
-rw-r--r--patternutils/commands/targs.py9
-rw-r--r--patternutils/commands/tmv.py9
-rw-r--r--patternutils/config.py9
4 files changed, 27 insertions, 9 deletions
diff --git a/patternutils/commands/pmatch.py b/patternutils/commands/pmatch.py
index ecf0a8e..c5800fe 100644
--- a/patternutils/commands/pmatch.py
+++ b/patternutils/commands/pmatch.py
@@ -78,7 +78,14 @@ def pmatch(
) -> None:
if use_predefined_pattern:
- regex_pattern, _ = config.load_template(regex_pattern, 'pmatch')
+ try:
+ regex_pattern, _ = config.load_template(regex_pattern, 'pmatch')
+ except FileNotFoundError:
+ click.secho('File not found!', fg='red', err=True)
+ raise SystemExit
+ except RuntimeError:
+ click.secho('Multiple files found!', fg='red', err=True)
+ raise SystemExit
try:
regex_pattern_c = re.compile(regex_pattern)
diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py
index ff5c0b1..9bdf213 100644
--- a/patternutils/commands/targs.py
+++ b/patternutils/commands/targs.py
@@ -70,7 +70,14 @@ def targs(
raise SystemExit
if use_predefined_template:
- command, template_engine = config.load_template(command, 'targs')
+ try:
+ command, template_engine = config.load_template(command, 'targs')
+ except FileNotFoundError:
+ click.secho('File not found!', fg='red', err=True)
+ raise SystemExit
+ except RuntimeError:
+ click.secho('Multiple files found!', fg='red', err=True)
+ raise SystemExit
try:
render = template.get_render_function(command, engine=template_engine)
diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py
index 3f618d2..7d0be21 100644
--- a/patternutils/commands/tmv.py
+++ b/patternutils/commands/tmv.py
@@ -62,7 +62,14 @@ def tmv(
raise SystemExit
if use_predefined_template:
- output_pattern, template_engine = config.load_template(output_pattern, 'tmv')
+ try:
+ output_pattern, template_engine = config.load_template(output_pattern, 'tmv')
+ except FileNotFoundError:
+ click.secho('File not found!', fg='red', err=True)
+ raise SystemExit
+ except RuntimeError:
+ click.secho('Multiple files found!', fg='red', err=True)
+ raise SystemExit
try:
render = template.get_render_function(output_pattern, engine=template_engine)
diff --git a/patternutils/config.py b/patternutils/config.py
index fc28e5d..e412548 100644
--- a/patternutils/config.py
+++ b/patternutils/config.py
@@ -18,9 +18,8 @@ def load_template(template_name: str, command_name: str) -> Tuple[str, str]:
elif len(files) == 0:
raise FileNotFoundError
elif len(files) > 1:
- click.secho('More then one file found!', fg='red', err=True)
- raise SystemExit
- except FileNotFoundError:
+ raise RuntimeError('Multiple files found!')
+ except (FileNotFoundError, RuntimeError):
raise
else:
output_pattern = template_lines.replace('\n', '')
@@ -31,13 +30,11 @@ def load_template(template_name: str, command_name: str) -> Tuple[str, str]:
template_engine = 'jinja2'
else:
template_engine = 'python'
-
- return output_pattern, template_engine
+ return output_pattern, template_engine
def find_templates(template_name: str, command_name: str=None) -> List[str]:
template_glob = '.'.join((template_name, '*'))
-
command_glob = '*' if command_name is None else command_name
command_glob = os.path.join(CONFIG_PATH, command_glob)
return glob.glob(os.path.join(command_glob, template_glob))