feat(cli): add bundled health app scaffold and init command
- 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
This commit is contained in:
31
openapi_first/cli.py
Normal file
31
openapi_first/cli.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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}")
|
||||
Reference in New Issue
Block a user