forked from s3rius/FastAPI-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
43 lines (33 loc) Β· 1.18 KB
/
__main__.py
File metadata and controls
43 lines (33 loc) Β· 1.18 KB
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
34
35
36
37
38
39
40
41
42
43
from pathlib import Path
from cookiecutter.exceptions import (FailedHookException,
OutputDirExistsException)
from cookiecutter.main import cookiecutter
from termcolor import cprint
from fastapi_template.cli import run_command
from fastapi_template.input_model import BuilderContext
script_dir = Path(__file__).parent
def generate_project(context: BuilderContext) -> None:
"""
Generate actual project with given context.
:param context: builder_context
"""
try:
cookiecutter(
template=f"{script_dir}/template",
extra_context=context.dict(),
default_config=BuilderContext().dict(),
no_input=True,
overwrite_if_exists=context.force,
)
except (FailedHookException, OutputDirExistsException) as exc:
if isinstance(exc, OutputDirExistsException):
cprint("Directory with such name already exists!", "red")
return
cprint(
"Project successfully generated. You can read information about usage in README.md"
)
def main() -> None:
"""Starting point."""
run_command(generate_project)
if __name__ == "__main__":
main()