Fixed templating
This commit is contained in:
parent
84fdb908ef
commit
37ff1782bb
16
new.py
16
new.py
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue