summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--patternutils/commands/patterncfg.py6
-rw-r--r--patternutils/config.py15
2 files changed, 12 insertions, 9 deletions
diff --git a/patternutils/commands/patterncfg.py b/patternutils/commands/patterncfg.py
index 1b37ba4..6844efc 100644
--- a/patternutils/commands/patterncfg.py
+++ b/patternutils/commands/patterncfg.py
@@ -1,7 +1,7 @@
import itertools
import os
import os.path
-from typing import Optional
+from typing import Literal, Optional
import click
@@ -65,11 +65,9 @@ def list() -> None:
def add(
template_engine: Optional[template.TemplateEngines], command: str, name: str
) -> None:
-
+ fileext: template.TemplateEngines | Literal["regex"] | None = template_engine
if command == "pmatch":
fileext = "regex"
- else:
- fileext = template_engine
filename = os.path.join(config.CONFIG_PATH, command, f"{name}.{fileext}")
click.edit(filename=filename)
diff --git a/patternutils/config.py b/patternutils/config.py
index b18b72c..0da5639 100644
--- a/patternutils/config.py
+++ b/patternutils/config.py
@@ -13,13 +13,18 @@ CONFIG_PATH = click.get_app_dir("patternutils")
REGEX_PROGRAMS = ("pmatch",)
TEMPLATE_PROGRAMS = ("tmv", "targs", "tln")
+
@overload
-def load_template(template_name: str, command_name: Literal["pmatch"]) -> tuple[str, Literal["regex"]]:
- ...
+def load_template(
+ template_name: str, command_name: Literal["pmatch"]
+) -> tuple[str, Literal["regex"]]: ...
+
@overload
-def load_template(template_name: str, command_name: Literal["tmv", "targs", "tln"]) -> tuple[str, Literal["python", "jinja2"]]:
- ...
+def load_template(
+ template_name: str, command_name: Literal["tmv", "targs", "tln"]
+) -> tuple[str, Literal["python", "jinja2"]]: ...
+
def load_template(
template_name: str, command_name: Optional[CommandNames]
@@ -64,7 +69,7 @@ def find_templates(
raise ValueError(f"{command_name} is not known!")
regex = re.compile(
- os.path.join(CONFIG_PATH, f"{path_sub_regex}", f"{template_name}\.{extension}")
+ os.path.join(CONFIG_PATH, f"{path_sub_regex}", f"{template_name}.{extension}")
)
files = filter(regex.search, glob.iglob(os.path.join(CONFIG_PATH, "*", "*")))