-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathgenerator.py
33 lines (24 loc) · 944 Bytes
/
generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
from typing import TypeVar
import typer
from cookiecutter.exceptions import OutputDirExistsException
from cookiecutter.main import cookiecutter
from pydantic.main import BaseModel
from manage_fastapi.config import TEMPLATES_DIR
from manage_fastapi.context import AppContext, ProjectContext
ContextType = TypeVar("ContextType", bound=BaseModel)
def fill_template(template_name: str, context: ContextType):
try:
cookiecutter(
os.path.join(TEMPLATES_DIR, template_name),
extra_context=context.dict(),
no_input=True,
)
except OutputDirExistsException:
typer.echo(f"Folder '{context.folder_name}' already exists. 😞")
else:
typer.echo(f"FastAPI {template_name} created successfully! 🎉")
def generate_app(context: AppContext):
fill_template("app", context)
def generate_project(context: ProjectContext):
fill_template("project", context)