chore: better template files list
All checks were successful
build / build (push) Successful in 1m55s
All checks were successful
build / build (push) Successful in 1m55s
This commit is contained in:
parent
160f16ca2b
commit
56c4981340
|
@ -1,4 +1,3 @@
|
|||
from importlib import resources
|
||||
from pathlib import Path
|
||||
from typing import Tuple, Type, cast
|
||||
|
||||
|
@ -17,11 +16,7 @@ def load_joj3_task_toml_answers() -> answer.Answers:
|
|||
language = cast(Type[answer.LanguageInterface], language)
|
||||
if inquirer.confirm("Load content from templates?", default=True):
|
||||
answers = inquirer.prompt(language.get_template_questions())
|
||||
templates_dir = resources.files(f"joj3_config_generator.templates").joinpath(
|
||||
language.name
|
||||
)
|
||||
template_file_path = answers["template_file"]
|
||||
template_file_content = Path(templates_dir / template_file_path).read_text()
|
||||
template_file_content: str = answers["template_file_content"]
|
||||
return answer.Answers(
|
||||
name=name, language=language, template_file_content=template_file_content
|
||||
)
|
||||
|
|
|
@ -33,16 +33,15 @@ class LanguageInterface(ABC):
|
|||
|
||||
@classmethod
|
||||
def get_template_questions(cls) -> List[Any]:
|
||||
templates_dir = resources.files(f"joj3_config_generator.templates").joinpath(
|
||||
cls.name
|
||||
)
|
||||
anchor = "joj3_config_generator.templates"
|
||||
templates_dir = resources.files(anchor).joinpath(cls.name)
|
||||
choices = []
|
||||
for entry in templates_dir.iterdir():
|
||||
if entry.is_file() and entry.name.endswith(".toml"):
|
||||
choices.append(entry.name)
|
||||
choices.append((entry.name, entry.read_text()))
|
||||
return [
|
||||
inquirer.List(
|
||||
"template_file",
|
||||
"template_file_content",
|
||||
message="Which template file do you want?",
|
||||
choices=choices,
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue
Block a user