From 37ff1782bb301fae36f0beca298b7e3f21c6d1bd Mon Sep 17 00:00:00 2001 From: hkc Date: Wed, 29 May 2024 12:29:25 +0300 Subject: [PATCH] Fixed templating --- new.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/new.py b/new.py index faeb4ad..c3d00a7 100644 --- a/new.py +++ b/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)