- ship OpenAPI-first health check template as package data - add CLI to copy scaffold into new project directories - include OpenAPI spec, routes, and bootstrap example - enable fast startup for OpenAPI-first services
32 lines
862 B
Python
32 lines
862 B
Python
import shutil
|
|
import argparse
|
|
from pathlib import Path
|
|
from importlib import resources
|
|
|
|
|
|
def copy_health_app_template(target_dir: Path) -> None:
|
|
"""
|
|
Copy the bundled health app template into a target directory.
|
|
"""
|
|
target_dir = target_dir.resolve()
|
|
target_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
with resources.files("fastapi_openapi_first.templates").joinpath("health_app") as src:
|
|
shutil.copytree(src, target_dir, dirs_exist_ok=True)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="FastAPI OpenAPI-first scaffolding tools"
|
|
)
|
|
parser.add_argument(
|
|
"path",
|
|
nargs="?",
|
|
default="health-app",
|
|
help="Target directory for the health app",
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
copy_health_app_template(Path(args.path))
|
|
print(f"Health app created at {args.path}")
|