Fixed templating

This commit is contained in:
Casey 2024-05-29 12:29:25 +03:00
parent 84fdb908ef
commit 37ff1782bb
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 8 additions and 8 deletions

16
new.py
View File

@ -39,8 +39,8 @@ for v in TEMPLATES_DIR.rglob("template.toml"):
templates[tpl.name] = tpl
name: Optional[str] = questionary.text("Project name").ask()
if not name:
project_name: Optional[str] = questionary.text("Project name").ask()
if not project_name:
exit(1)
template: Optional[ProjectTemplate] = questionary.select("Template", [
@ -61,7 +61,7 @@ parameters = questionary.prompt([
if not parameters:
exit(1)
project_dir = Path(name)
project_dir = Path(project_name)
project_dir.mkdir(parents=True, exist_ok=True)
for base, dirs, files in template.path.walk():
@ -70,16 +70,16 @@ for base, dirs, files in template.path.walk():
for filename in files:
in_path = base / filename
name = str(in_path.relative_to(template.path))
out_path = project_dir / name
if name == "template.toml":
file_name = str(in_path.relative_to(template.path))
out_path = project_dir / file_name
if file_name == "template.toml":
continue
elif name in template.templates:
elif file_name in template.templates:
print("TMPL", out_path)
with in_path.open("r") as fp_in:
with out_path.open("w") as fp_out:
for line in fp_in:
line = line.replace("__PROGNAME", name)
line = line.replace("__PROGNAME", project_name)
for param in template.parameters:
line = line.replace(f"__{param}", parameters[param])
fp_out.write(line)