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