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 pathlib import Path
|
||||||
from typing import Tuple, Type, cast
|
from typing import Tuple, Type, cast
|
||||||
|
|
||||||
|
@ -17,11 +16,7 @@ def load_joj3_task_toml_answers() -> answer.Answers:
|
||||||
language = cast(Type[answer.LanguageInterface], language)
|
language = cast(Type[answer.LanguageInterface], language)
|
||||||
if inquirer.confirm("Load content from templates?", default=True):
|
if inquirer.confirm("Load content from templates?", default=True):
|
||||||
answers = inquirer.prompt(language.get_template_questions())
|
answers = inquirer.prompt(language.get_template_questions())
|
||||||
templates_dir = resources.files(f"joj3_config_generator.templates").joinpath(
|
template_file_content: str = answers["template_file_content"]
|
||||||
language.name
|
|
||||||
)
|
|
||||||
template_file_path = answers["template_file"]
|
|
||||||
template_file_content = Path(templates_dir / template_file_path).read_text()
|
|
||||||
return answer.Answers(
|
return answer.Answers(
|
||||||
name=name, language=language, template_file_content=template_file_content
|
name=name, language=language, template_file_content=template_file_content
|
||||||
)
|
)
|
||||||
|
|
|
@ -33,16 +33,15 @@ class LanguageInterface(ABC):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_template_questions(cls) -> List[Any]:
|
def get_template_questions(cls) -> List[Any]:
|
||||||
templates_dir = resources.files(f"joj3_config_generator.templates").joinpath(
|
anchor = "joj3_config_generator.templates"
|
||||||
cls.name
|
templates_dir = resources.files(anchor).joinpath(cls.name)
|
||||||
)
|
|
||||||
choices = []
|
choices = []
|
||||||
for entry in templates_dir.iterdir():
|
for entry in templates_dir.iterdir():
|
||||||
if entry.is_file() and entry.name.endswith(".toml"):
|
if entry.is_file() and entry.name.endswith(".toml"):
|
||||||
choices.append(entry.name)
|
choices.append((entry.name, entry.read_text()))
|
||||||
return [
|
return [
|
||||||
inquirer.List(
|
inquirer.List(
|
||||||
"template_file",
|
"template_file_content",
|
||||||
message="Which template file do you want?",
|
message="Which template file do you want?",
|
||||||
choices=choices,
|
choices=choices,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user