Files
Vishesh 'ironeagle' Bangotra 2f444a93ad
All checks were successful
continuous-integration/drone/tag Build is passing
doc changes from fastapi openapi first to openapi first. added cli docs
2026-01-10 17:43:52 +05:30

90 lines
2.4 KiB
Python

"""
openapi_first.cli
========================
Command-line interface for FastAPI OpenAPI-first scaffolding utilities.
This module provides a small, focused CLI intended to help developers
quickly bootstrap OpenAPI-first FastAPI services using bundled project
templates.
Currently supported scaffolds:
- Health check service (minimal OpenAPI-first application)
The CLI copies versioned templates packaged with the library into a
user-specified directory, allowing rapid local development without
manual setup.
"""
import argparse
import shutil
from pathlib import Path
from importlib import resources
def copy_health_app_template(target_dir: Path) -> None:
"""
Copy the bundled OpenAPI-first health app template into a directory.
This function copies a fully working, minimal OpenAPI-first FastAPI
health check application from the package's embedded templates into
the specified target directory.
The target directory will be created if it does not already exist.
Existing files may be overwritten.
Parameters
----------
target_dir : pathlib.Path
Destination directory into which the health app template
should be copied.
Raises
------
FileNotFoundError
If the bundled health app template cannot be located.
"""
target_dir = target_dir.resolve()
target_dir.mkdir(parents=True, exist_ok=True)
with resources.files("openapi_first.templates").joinpath(
"health_app"
) as src:
shutil.copytree(src, target_dir, dirs_exist_ok=True)
def main() -> None:
"""
Entry point for the FastAPI OpenAPI-first CLI.
Parses command-line arguments and initializes a new OpenAPI-first
health check application by copying the bundled template into the
specified directory.
If no target path is provided, the scaffold is created in a directory
named ``health-app`` in the current working directory.
Example
-------
Create a health app in the default directory::
openapi-first
Create a health app in a custom directory::
openapi-first my-service
"""
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}")